Koozali.org: home of the SME Server

Contribs.org Forums => General Discussion => Topic started by: aussierob on May 13, 2008, 09:20:39 AM

Title: manually decoding an email
Post by: aussierob on May 13, 2008, 09:20:39 AM
I am hoping someone can point ignorant me in the right direction!
If I am inappropriate in my request, please ignore it and forgive me.

I want to scan files in a certain Maildir/new to see if the Subject contains "some text".
If it does I want to 'extract' the file attachment in that email which shows per following...

Content-Type: application/vnd.ms-excel;
 name="test.csv"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="test.csv"

I would prefer to drive it with a perl script, soemthing along the lines of

open (LS, "ls /home/e-smith/files/users/xxx/Maildir/new/* |");
while (<LS>) {
        $line= $_;
        chomp ($line);
        $line =~ s/\s+$//;
        #IF SUBJECT HAS 'SOME TEXT'
            `./processemail.pl $line`;
            `rm $line* `;
 }

and then processemail.pl can do the file extraction (if is easier the subject test can be in there too, calling another process if preferable)

TIA Rob
Title: Re: manually decoding an email
Post by: m on May 13, 2008, 05:43:11 PM
Use the program 'mimedump'. It prints all MIME parts on STDOUT and saves non-text parts to disk.
Title: Re: manually decoding an email
Post by: CharlieBrady on May 14, 2008, 08:17:39 PM
I want to scan files in a certain Maildir/new to see if the Subject contains "some text".

No, I don't think you do. I think you want to check all newly delivered messages, as they are delivered. You would do that by putting a line like this in your .qmail file (via a custom user template):

...
| condredirect xxx-process headermatch 'Subject: some text'
...

(where xxx is the userid which receives the mail) and then you want to add a ~xxx/.qmail-process file which contains:

| perl script_to_extract_what_you_are_interested_in.pl

Messages are only temporarily in Maildir/new/, and you will miss some messages if a mail client has the folder open, so don't try to do it the way you propose.
Title: Re: manually decoding an email
Post by: aussierob on May 22, 2008, 03:43:09 AM
No, I don't think you do.......
.....Messages are only temporarily in Maildir/new/, and you will miss some messages if a mail client has the folder open, so don't try to do it the way you propose.

Thanks for your exact comment as usual, Charlie:
guys like you are much appreciated by many like me  8)
(in this case though I am believe I am ok as it is a special user that will not have a mail client popping emails, I plan to just check 'em and rm them)
Title: Re: manually decoding an email
Post by: aussierob on May 22, 2008, 04:19:45 AM
Use the program 'mimedump'. It prints all MIME parts on STDOUT and saves non-text parts to disk.

Thanks for the advice:
- I found mimedump at CPAN, but the options are mindnumbingly large.

1. do you know the simple way to process a single filename
2. will I need any other file ( I am using SME Server 6.0.1-01 and cannot easily upgrade)
TIA Rob
Title: Re: manually decoding an email
Post by: CharlieBrady on May 22, 2008, 04:24:37 PM
1. do you know the simple way to process a single filename

Use a .qmail file and a program which reads from standard input, as I have already described.
Title: Re: manually decoding an email
Post by: m on May 23, 2008, 05:40:26 PM
- I found mimedump at CPAN, but the options are mindnumbingly large.
I have referred to the program mimedump not the perl module. If you want to write perl code consider using perl-MIME-tools which are already installed on SME7. Examples how to use them can be found in /usr/share/qpsmtpd/plugins/tnef2mime