LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-13-2003, 09:50 PM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
How to locate and extract a mail from a *nix mailbox?


I would like to write a script that automatically locates and extracts a mail in a *nix mailbox and sends it to someone.
The problem is as follows:
I use a procmail-based e-mail sanitizer, that sends sanitized mails to the users' mailboxes, while the original (unsanitized) mails are backed up. Sometimes an important user is not satisfied with the look of the sanitized (mostly html) mail. I would like to allow him get the original (unchanged) mail on his own responsibility.
A possible way of this would be to let him send the sanitized message to a specific address (to an auto-responding element of the mail system); the mail system should automatically identify the message in the backup mailbox and send the original (unchanged) message to the user.
The headers of the sanitized and original messages are almost identical, except that the first has some additional lines added by SpamAssassin and the Sanitizer.
Maybe the date of receipt, sender and the subject could be used to locate the message in the backup mailbox, or are there better data in the header for identification?
How to find the boundaries of each message in the mailbox and how to extract a specific message (cat, grep, sed, formail?)?

Last edited by J_Szucs; 01-13-2003 at 10:16 PM.
 
Old 01-13-2003, 11:56 PM   #2
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,153

Rep: Reputation: 56
I would say that by copying and chowning the backup file to /var/spool/mail/someuser then that user would own the mail. Then an email client can filter the mail by the To: username in the headers and put them in seperate mail files, which could then be chowned and copied to the proper user
 
Old 01-14-2003, 03:51 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Just an idea, but if you could have procmail filter incoming mail using formail to tack on the Message-Id in an extra header (like X-OrigMessage-Id), and they send it to a designated address, and then let procmail find the orig by comparing X-OrigMessage-Id and Message-Id I think that could work w/o much user trouble. Statistical chance for Message-Id's to be identical is much smaller than for a to|from|subject set I'd say.
 
Old 01-14-2003, 10:44 AM   #4
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Thank you for the X-Message-Id tip, it is a good idea.

However I am still stucked at the mail extraction problem:
Reading the procmail and the formail manuals I suspect that I could use formail to split the backup mailbox into messages and maybe they could be fed to procmail (called with a specific procmailrc file) to filter out the rigth message into the user's mailbox using the X-Message-Id.
However, I would rather avoid calling procmail the second time to filter the message, since I regard it as a too heavy tool to be called two times on the same message. The route of the message would be rather complicated:
user's mailbox > procmail > spam filter > sanitizer > procmail > formail (splitting) > procmail (filter out the right message) > user's mailbox
Maybe the spam filter and the sanitizer could be avoided, but it still seems rather heavy because of the two calls of procmail:
user's mailbox > procmail > formail (splitting) > procmail (filter out the right message) > user's mailbox
I also suspect that there would not be two procmail calls, but as many as there are messages in the backup mailbox (formail would call procmail for each message).
I would rather replace the second procmail call with a call to a lightweight utility.

Last edited by J_Szucs; 01-14-2003 at 10:47 AM.
 
Old 01-14-2003, 11:28 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Remote user|fetchmail process to local spool:
Code:
    remote_uid                       (maybe store msguid in lookup table?)
             |                      /cp ->backup_spool
        sendmail->procmail_sanitizer->user_spool
                             |
                    fetchmail
Ok, now user wants "real" message, fires off to designated address:

Code:
    remote_uid
             |                        
       sendmail->procmail
                 |     \grep backup_spool -e msguid ->user_spool
               fetchmail
Or am I misunderstanding something?
You already have got the sanitizer running tru procmail, I hope the spam filter as well? Procmail does have some crude form of if-then-else, for instance availability of X-Orig-Message-Id header could lead to running a retrieve, else the sanitizer/spam filter are run. Also, if you rotate backup_spool per week/month/user? How much strain would that put on the server?

If I had a choice I'd be running all processing way before it hits the users spool/dir.

Last edited by unSpawn; 01-14-2003 at 11:33 AM.
 
Old 01-15-2003, 10:47 AM   #6
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Wow! That's it!

If I store each incoming message in a separate backup file, then I can use grep to find the right message in the backup, and simply append that to the user's mailbox. No need to call procmail again!
If the message backup file gets the message ID as filename, then even grep can be omitted (supposed that the message ID cannot contain characters that are forbidden in filenames, which I hope).

It seems now very easy.
Plus it is even easier to clean up the backups of old messages. This I made rare and manually before, now I can easily clean up old backup files by the date of creation.

Thank you for your help!

Last edited by J_Szucs; 01-15-2003 at 09:11 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Qmail problem: ISP mail and virtual mail, "sorry no mailbox, here by that user" barryw Linux - Networking 7 05-28-2005 12:43 PM
qmail delivering mail but not to mailbox ServerStorm Linux - Software 9 01-13-2005 10:39 AM
KVim mail agent has emptied my mailbox! milad126 Suse/Novell 0 11-22-2004 06:07 PM
pine: moving mail to another mailbox dARkHunTEr Linux - Software 0 05-08-2004 06:31 AM
Postfix not delivering mail to mailbox DeVryGuy Linux - Software 13 09-22-2003 12:43 AM


All times are GMT -5. The time now is 03:28 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration