wilde: utils/admin tagedmailnote, NONE, 1.1 tagedmailnote.README, NONE, 1.1

cvs at kolab.org cvs at kolab.org
Tue Jan 19 11:47:06 CET 2010


Author: wilde

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv17654

Added Files:
	tagedmailnote tagedmailnote.README 
Log Message:
Added tagedmailnote script and readme.
A simple script allowing to send a notification to an arbitrary email
address upon arrival of email which contains a configurable tag in the
subject line.


--- NEW FILE: tagedmailnote ---
#!/usr/bin/env python
# coding=utf-8
#
# Copyright (C) 2005, 2006, 2007, 2009, 2010 by Intevation GmbH
# Author(s):
# Thomas Arendsen Hein <thomas at intevation.de>
# Sascha Wilde <wilde at intevation.de>
#
# This program is free software under the GNU GPL (>=v2)
# Read the file COPYING coming with the software for details.
#
# In addition, as a special exception, Intevation GmbH gives
# permission to link the code of this program with the OpenSSL
# library (or with modified versions of OpenSSL that use the same
# license as OpenSSL), and distribute linked combinations including
# the two. You must obey the GNU General Public License in all
# respects for all of the code used other than OpenSSL. If you
# modify this file, you may extend this exception to your version
# of the file, but you are not obligated to do so. If you do not
# wish to do so, delete this exception statement from your version.

"""
tagmailnote

Usage: tagmailnote Tag From-Address To-Address

Sends a mail to To-Address if the mail on stdin contains Tag in its subject.
"""

notesubject = "A mail tagged URGENT arrived at your company account."
notetext = """A mail with the keyword URGENT in the subject was send to your 
company account.  Visit your company as soon as possible."""

import sys, smtplib, md5, mimetools, MimeWriter, rfc822, quopri, StringIO

def sendmail(fromaddr, toaddr, subject, text):
    msgid = "<%s@%s>" % (md5.new(mimetools.choose_boundary()).hexdigest()[:16],
                         fromaddr.split('@')[1])
    message = StringIO.StringIO()
    writer = MimeWriter.MimeWriter(message)
    writer.addheader('MIME-Version', '1.0')
    writer.addheader('From', fromaddr)
    writer.addheader('To', toaddr)
    writer.addheader('Subject', subject)
    writer.addheader('Message-Id', msgid)
    writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
    body = writer.startbody('text/plain; charset="utf-8"')

    # Add body
    body.write(quopri.encodestring(text))

    # send the mail
    smtp = smtplib.SMTP('localhost')
    smtp.sendmail(fromaddr, toaddr, message.getvalue())
    smtp.quit()


if __name__ == '__main__':
    if len(sys.argv) >= 4:
        tag, fromaddr, toaddr = sys.argv[1:4]
        mail = rfc822.Message(sys.stdin)
        subject = mail.getfirstmatchingheader("Subject")[0]
        if subject and subject.find(tag) > -1:
            sendmail(fromaddr, toaddr, notesubject, notetext)
    else:
        print __doc__

--- NEW FILE: tagedmailnote.README ---
Using tagedmailnote with the Kolab server:
------------------------------------------

When a mail to foo at example.net contains the tag "[URGENT]" in the
subject an notification email shall be send to bar at example.com.

First copy the tagedmailnote script to /kolab/sbin/, so it can be
executed by the user kolab-n.

Add a new service to /kolab/etc/kolab/templates/master.cf.template:

 # service                     type private unpriv chroot wakeup maxproc cmd
 tagedmailnote-bar-example-com unix -       n      n      -      -       pipe
     user=kolab-n argv=/kolab/sbin/tagedmailnote
     [URGENT] postmaster at example.net bar at example.com

Connect this service to a new address by adding the following line to
the file /kolab/etc/kolab/templates/transport.template:

 foo-taged at example.net  tagedmailnote-bar-example-com:

Now you can use /kolab/etc/kolab/templates/virtual.template to forward mails
to the mailattach-bar-example-com subdomain:

 foo at example.net  @example.net, foo-taged at example.net

To activate these changes, run /kolab/sbin/kolabconf

Instead of modifying virtual.template you could use Sieve scripts to forward
mails to the new address, too.





More information about the commits mailing list