Advertising | Mobile Phone | Credit Cards | Loans | WOW Gold
Command line mail programs [Archive] - ZGeek

PDA

View Full Version : Command line mail programs


C0V3R
17-04-2004, 03:28 PM
I've gotta write an app that detatches all attatchments coming into a given email account and then does stuff with them, and deletes the email when its done. I have no problem with the majority of it, but does anyone know of a decent command line program (pref. open source/gnu etc) that can save attatchments etc from command line arguments, or know of how to pipe in the appropriate commands sequentially to something like pine from perl?

druid
18-04-2004, 07:40 AM
This may not quite solve your whole problem (not sure if I understood it) but hopefully it can get you started: mailx (http://www.rahul.net/cgi-bin/userbin/man?topic=mailx&section=1). (that's for sending)

Iirc it goes something like this:

mailx -s"subject line" me@privacy.net < not_a_virus.jpg.vbs

For processing upon arrival you could use the .procmailrc (http://www.columbia.edu/acis/email/delivery/procmail/man-procmailrc) file, depending on the mail system of course.

Uther Pendragon
18-04-2004, 01:47 PM
COV3R,
I do something very similar to this on a few servers at work, I have fetchmail installed on a server which gets run as a cron job, the user that runs the cronjob has a .fetchmailrc in their home directory, this has settings which tell fetchmail to use a different program to deliver the mail, in this case a perl script that was hacked up by a colleague and myself. This script then pulls apart the attachments and "does stuff" to them before deleting the email. I can't remember the specifics of the script as it was done ages ago, but if you would like i can dig up the script and email it to you on Monday from work.

C0V3R
18-04-2004, 02:51 PM
That'd be great uther, its pretty much what I've been looking at doing, though I was hoping that someone may have already designed one of these wheels, so to speak. Ive come up with a couple of bash commands by which I can dump whole emails using "mail", then I'll probably have to write an attatchment getter, a processor (to decode a base 64 enc attatchment).

- fetchmail/getmail/etc to a local file
- delete email from server (ideally this would be during the for loop but may be impractical)

for loop through emails
- echo $i | mail -f > file$i
- do stuff to get the attachment here
- decode attatchment
- save to file
- do stuff with the attachment
- echo 'd $i' | mail -f > output //delete mail item from local file
end loop

Uther Pendragon
19-04-2004, 12:47 AM
Yeah if i remember I will post some code up here tomorrow from work. its actually quite easy to do all this stuff with fetchmail, easier than I thought it would be anyway.

C0V3R
19-04-2004, 12:53 AM
Good to hear, thanks!

Uther Pendragon
19-04-2004, 03:03 PM
Here is the contents of my .fetchmailrc (passwords removed to protect the guilty). I have attached the contents of the extract_attached script (sanitized also)

set no bouncemail
defaults:
antispam -1
batchlimit 100
mda /home/<some dir>/extract_attached

poll mail.your.server protocol pop3 username "<username>" password "<password>"