Find the answer to your Linux question:
Results 1 to 4 of 4
HI, I am new to linux and postfix. I would really appreciate any help. I wrote a python script to extract mime-attachments from email received at the postfix server but ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3

    Postfix Filter


    HI,

    I am new to linux and postfix. I would really appreciate any help. I wrote a python script to extract mime-attachments from email received at the postfix server but only for the local user i.e. for the ones saved in the folder /var/mail/$USER. But now I want to run the same script before the mails are dropped into the respective mailboxes, so I can do the same for all the recipients. For this I looked at the following link:

    Postfix After-Queue Content Filter
    and made the specified changes in the master.cf file for the Simple Content Filter.

    My python script: extractattachmentnew.py


    #!/usr/bin/env python

    import sys, os, string, mimetools, multifile, email, errno, mimetypes
    import mailbox
    import pdb
    import MySQLdb
    from optparse import OptionParser
    from email.Utils import parsedate
    import random
    import md5

    directory = "/home/scofmon/Desktop/Spam Analysis Stuff/Extracted Mail"

    def extract(msg):
    for part in e_msg.walk():
    try:
    conn = MySQLdb.connect(db="spamattachments",host="localho st",user="",passwd="");
    #................
    #done something here

    conn.close()
    print "Disconnected<br/>"
    #sys.exit(0)

    def main():
    msgfile = "/var/mail/scofmon"
    fp = open(msgfile, 'r')
    mb = mailbox.UnixMailbox(fp, email.message_from_file)
    msg = mb.next()
    while msg is not None:
    #document = msg.fp.read()
    extract(msg)
    msg = mb.next()
    fp.close()
    print "fp disconnected"

    if __name__ == "__main__":
    main()

    changes in master.cf:

    smtp inet n - - - - smtpd
    -o content_filter=filter:dummy

    filter unix - n n - 10 pipe
    flags=Rq user=scofmon argv=/home/scofmon/Desktop/spam-analysis-stuff/extractattachmentnew.py


    This script works fine. But, as I said i need to change my python script to work NOT on mails in /var/mail/scofmon but rather at the server queue itself before the mails are dropped into the mailbox. I able not able to understand how this filter thing works.

    1. Now that I have made changes to main.cf, are the files directly sent to my script?
    2. How can my script access these mails? through command line argumengts. through some pre-defined variable?
    3. if my script is not running all the time, where would the mails go?
    4. The file sent to the script is a single mail file as was in the case of /var/mail/scofmon or its multiple files?

    I might have asked some really stupid or confusing questions, but I am totally confused right now and hope someone could help me out.

    Thnx a lot in advance.

  2. #2
    Just Joined!
    Join Date
    Nov 2008
    Posts
    8
    i think it might be much easier if you use mail filtering tools like amavisd-new or others. These kind of tools can be set up where postfix will pass the mail to them for scanning and pass back to postfix. It is very flexiable, and from what you describing what you want to do, i think this would be easily set up.

    kevin

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3

    Smile Thanx a lot :)

    Hi,

    I am new to amavisd-new. I'll install it and hopefully shud be able to make things work properly. Thnx a lot for your kind help . I really appreciate it.

    -Monica.

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    3
    Hi all,

    I installed amavisd-new version 2.5.3-1. And as I mentioned above, I want to send all the mails (globally) to amavisd and from there call my external python script to perform some function on each mail.

    I have 2 ques:
    1. I wanted to configure amavisd so that all mails go to amavisd. I referred to the following link:
    http://www.ijs.si/software/amavisd/README.postfix (since I am using postfix as the MTA).

    The link talks about the config file amavisd.conf. However with the package that I got from the repos, there is no single conf file. However various files such as 50-user, 15-content_filter_mode, 20-debian_defaults, etc.

    So I dont get, in which file I need to make the specified changes. (I am using ubuntu hardy heron).

    2. Is it possible to call an external script from amavisd and run it on each mail received by the amavisd. If yes, how? Is there some online resource for that?

    Thank you in advance for the help.

    cheers,
    Monica.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •