[Limacute-commit] r166 - trunk/tools/imap2dspam

jhf at projects.linpro.no jhf at projects.linpro.no
Wed May 16 09:51:33 CEST 2007


Author: jhf
Date: 2007-05-16 09:51:32 +0200 (Wed, 16 May 2007)
New Revision: 166

Added:
   trunk/tools/imap2dspam/INSTALL
   trunk/tools/imap2dspam/TODO
Modified:
   trunk/tools/imap2dspam/imap2dspam.py
Log:
Translate to english anti-spam manual, add meta information.

Added: trunk/tools/imap2dspam/INSTALL
===================================================================
--- trunk/tools/imap2dspam/INSTALL	2007-05-15 07:05:24 UTC (rev 165)
+++ trunk/tools/imap2dspam/INSTALL	2007-05-16 07:51:32 UTC (rev 166)
@@ -0,0 +1,8 @@
+Set up a working cyrus.
+  Default delivery of spam messages to "INBOX/Spam" folder.
+Set up a working dspam, with the preferences:
+  Preference "signatureLocation=headers"
+  PgSQLUIDInSignature     on
+Test imap2dspam.py.
+Start a cronjob that invokes imap2dspam.py regularly, for instance
+once every hour.

Added: trunk/tools/imap2dspam/TODO
===================================================================
--- trunk/tools/imap2dspam/TODO	2007-05-15 07:05:24 UTC (rev 165)
+++ trunk/tools/imap2dspam/TODO	2007-05-16 07:51:32 UTC (rev 166)
@@ -0,0 +1,4 @@
+# Proper error code validation of all imap return commands.
+# Localization 
+# Code cleanup, move initialization into main()
+# Better INSTALL instructions.

Modified: trunk/tools/imap2dspam/imap2dspam.py
===================================================================
--- trunk/tools/imap2dspam/imap2dspam.py	2007-05-15 07:05:24 UTC (rev 165)
+++ trunk/tools/imap2dspam/imap2dspam.py	2007-05-16 07:51:32 UTC (rev 166)
@@ -59,6 +59,7 @@
 parser.add_option("--spambox", metavar="Mailbox",default="INBOX/Spam",type="string",help="The name of the spam folder.")
 parser.add_option("--spam_expire", metavar="Days",default=30,type="int",help="Delete spam after the given number of days.")
 parser.add_option("--unsurebox", metavar="Mailbox",default="INBOX/Unsure",type="string",help="The name of the unsure folder.")
+parser.add_option("--dspam_url", metavar="URL",type="string",help="The URL to the dspam control center. Example https://dspam.domain.org/")
 parser.add_option("--trashbox", metavar="Mailbox",default="INBOX/Trash",type="string",help="The name of the trash folder.")
 parser.add_option("--imap_port", metavar="HOST",default=143,type="int",help="The port to connect to on the imap server.")
 parser.add_option("--log", metavar="PATH",default="/dev/null",type="string",help="The path to the log file.")
@@ -74,43 +75,43 @@
     if not getattr(options,required):
         parser.error("You must provide %(required)s"%vars())
 
-guide = """Hei!
-Denne serveren har et automatisk anti-spam system, som tilpasser seg dine ønsker.
-Det serveren tror er spam, blir plassert i mappen %(spambox)s.
-Det serveren er usikker på hva er blir plassert i mappen %(unsurebox)s.
-Resten blir levert som vanlig.
+guide = """Hi!
+This server has an automatic anti-spam system, that adapts to your needs.
+Spam is delivered to the folder %(spambox)s.
+Regular email is delivered as usual.
+If the server is unsure about a message, it is placed in %(unsurebox)s.
 
-Dersom du får en spam i din vanlige epost, flytt den til %(spambox)s mappen.
-Da vil maskinen lære å kjenne igjen at denne typen meldinger er spam.
-Når maskinen har lært fra en melding i %(spambox)s mappen, blir meldingen slettet.
-Epost i %(spambox)s mappen som er eldre enn %(spam_expire)d dager blir 
-automatisk slettet.
+If you get spam in your regular email, move it to the %(spambox)s folder.
+The server will learn to recognize this kind of message as spam.
+When the server has learnt from a spam message in the %(spambox)s folder, the message is deleted.
+Email in the %(spambox)s folder, that are older than %(spam_expire)d days
+are automatically deleted.
 
-Dersom du får en epost du vil ha i din %(spambox)s mappe, 
-flytt den til den mappen du vil ha eposten i.
-Da vil maskinen lære at slik epost vil du ha.
+If you get a non-spam (ham) email in your %(spambox)s folder,
+move the email to the folder of your choice. 
+The server will recognize these kind of email are not spam, 
+and will learn to recognize that.
 
-Resten av denne eposten inneholder koder som serveren bruker til å 
-optimalisere søkingen etter meldinger for å analysere hvilke meldinger
-som er spam og ikke. Serveren trenger at denne eposten ligger i %(unsurebox)s
-mappen.
-Datoen for denne eposten angir når serveren sist lærte dine preferanser å 
-kjenne.
+The rest of this email contains codes that the server uses to 
+optimize the search for spam and non-spam (ham) messages.
+The server requires this message to be placed in the %(unsurebox)s
+folder.
+The date for this email reveals when the server last learned your 
+preferences.
 
-Du kan også få serveren til å ikke levere spam i %(spambox)s, men 
-heller ha det i en egen kø på serveren.
-
-Dette kan du ordne fra https://dspam.hex.no/ med brukernavn %(uid)s og
-ditt vanlige epost passord.
+You can also keep the server from delivering spam to yor %(spambox)s, 
+and rather keep the spam in a queue at the server.
+That can be achieved by logging in at %(dspam_url)s with username 
+%(uid)s and your regular email password.
 """
 
 tech_preamble = """
-For de teknisk interesserte kan det nevnes at kodene er lesbare med
-python. Det lagres en dict som husker sett siste epost.
+For the technically inclined, the codes are readable by python. 
+A stat dictionary with the last seen email is maintaned:
 state = dict()
-Vedlegget er kodet med 
+The attachment is produced with
 part = base64.encodestring(lzip.compress(repr(state)))
-Vedlegget kan leses med
+The attachment can be read with
 state = eval(lzip.decompress(base64.decodestring(part)))
 """
 
@@ -280,7 +281,7 @@
             uidnext = uidnext_pattern.findall(data[0])[0]
             if uidnext <= state[mailbox]:
                 # There are no new messages in this folder
-                logging.debug("No new messages since last check.")
+                logging.debug("No new messages in %(mailbox)s since last check."%vars())
                 continue
             wanted_range = str(state[mailbox])+":"+str(uidnext)
             # For folders with uids higher than lastseen
@@ -304,8 +305,10 @@
                         command = "sudo /usr/bin/dspamc --process --class=spam --source=error --user %(localpart)s@%(domain)s --signature=%(signature)s" % vars() 
     
                     result = getoutput(command)
+                    # TODO
+                    # Error handling based on result.
                 if mailbox == spambox:
-                    # if result OK
+                    # Code advances here if previous results are OK
                     logging.debug("Marking message %(message_uid)s for deletion"%vars())
                     # then mark message for deletion
                     (result,data) = imap_connection.uid('store',message_uid, '+FLAGS', r'(\Deleted)')
@@ -314,7 +317,7 @@
             state[mailbox] = uidnext
    
         if state == state_orig and expire and expire == spam_expire:
-            logging.debug("No changes in which messages that has been analysed, not creating new state.")
+            logging.debug("All messages previously analysed, keeping old state.")
         else:
             logging.debug("Creating updated server state in %(unsurebox)s."%vars())
             # Create status email with Message-id cybar-state
@@ -339,13 +342,13 @@
             state_part.add_header('Content-Disposition', 'attachment', filename=state_name)
             #state_part = MIMEText(repr(mailboxes),'x-python')
             message.attach(state_part)
-            # Find all old states
+            # Find all old state messages
             (result,data) = imap_connection.select(unsurebox)
             (result,data) = imap_connection.uid('search',None,'HEADER','Message-id',cyrus_state_id)
             old_state_uids = filter(lambda s:len(s) > 0,data[0].split(' '))
-            # Insert new state
+            # Insert new state message
             (result,data) = imap_connection.append(unsurebox,'()','',message.as_string())
-            # Delete old states 
+            # Delete old state messages 
             for old_state_uid in old_state_uids:
                 (result,data) = imap_connection.uid('store',old_state_uid, '+FLAGS', r'(\Deleted)') 
             imap_connection.close()



More information about the Limacute-commit mailing list