]> git.madduck.net Git - etc/mailfilter.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

checkin of tickler processor
authormartin f. krafft <madduck@madduck.net>
Sun, 26 Aug 2007 19:52:55 +0000 (21:52 +0200)
committermartin f. krafft <madduck@madduck.net>
Sun, 26 Aug 2007 19:52:55 +0000 (21:52 +0200)
bin/process-tickler [new file with mode: 0755]

diff --git a/bin/process-tickler b/bin/process-tickler
new file mode 100755 (executable)
index 0000000..c853294
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/python2.5
+# -*- coding: utf-8 -*-
+#
+# process-tickler – process message in tickler maildir
+#
+# Copyright © martin f. krafft <madduck@debian.org>
+# Released under the terms of the Artistic Licence 2.0
+#
+
+import mailbox
+import os
+import sys
+import time
+
+HOME = os.getenv('HOME')
+MAILDIR = os.path.join(HOME, '.maildir')
+TICKLER_DIR = os.path.join(MAILDIR, '.tickler')
+INBOX_DIR = MAILDIR
+
+tmd = mailbox.Maildir(TICKLER_DIR)
+imd = mailbox.Maildir(INBOX_DIR)
+msgids = dict()
+
+def move_to_inbox(key):
+    msg = tmd.get_message(key)
+    print >>sys.stdout, 'I: move message %s to inbox' % key
+    imd.add(msg)
+    tmd.discard(key)
+
+for key, msg in tmd.iteritems():
+    msgid = msg.get('Message-Id')
+    if msgid is None:
+        print >>sys.stderr, 'W: message without ID: ' + key
+        move_to_inbox(key)
+
+    tickle = msg.get('X-Tickle')
+    if tickle is None:
+        print >>sys.stderr, 'W: message without tickle information: ' + key
+        move_to_inbox(key)
+
+    if msgids.get(msgid, None) is None:
+        msgids[msgid] = list()
+    msgids[msgid].append((int(tickle.split(' ', 1)[0]), key, msg))
+
+for msgid, msgs in msgids.iteritems():
+    msgs.sort()
+    prev_tickle = None
+    for tickle, key, msg in msgs:
+        if tickle == prev_tickle:
+            print >>sys.stderr, 'I: discarding duplicate %s of message %s' % (key, msgid)
+            tmd.discard(key)
+            continue
+        prev_tickle = tickle
+
+        t = time.time()
+        if t >= tickle:
+            move_to_inbox(key)
+        else:
+            print >>sys.stdout, 'I: message %s still has %d seconds' % (key,
+                    int(tickle - t))