X-Git-Url: https://git.madduck.net/etc/mailfilter.git/blobdiff_plain/bda8338eb8f1274f9a1dec73bdb47f80cfe9413f..0a76b0032d4004450bee10eded1a8bdb79042c22:/bin/process-tickler diff --git a/bin/process-tickler b/bin/process-tickler index 0c3839f..28b6c5e 100755 --- a/bin/process-tickler +++ b/bin/process-tickler @@ -15,29 +15,32 @@ import time HOME = os.getenv('HOME') MAILDIR = os.path.join(HOME, '.maildir') TICKLER_DIR = os.path.join(MAILDIR, '.tickler') -INBOX_DIR = MAILDIR +DEST_DIR = os.path.join(MAILDIR, '.resubmit') tmd = mailbox.Maildir(TICKLER_DIR) -imd = mailbox.Maildir(INBOX_DIR) +dmd = mailbox.Maildir(DEST_DIR) msgids = dict() -def move_to_inbox(key): +def resubmit(key): msg = tmd.get_message(key) - print >>sys.stdout, 'I: move message %s to inbox' % key - msg.add_header('X-Tickle-Delivered', time.strftime('%c')) - imd.add(msg) + print >>sys.stdout, 'I: resubmit message %s' % key + if msg.has_key('X-Tickle-Delivered'): + msg.replace_header('X-Tickle-Delivered', time.strftime('%c')) + else: + msg.add_header('X-Tickle-Delivered', time.strftime('%c')) + dmd.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) + resubmit(key) tickle = msg.get('X-Tickle') if tickle is None: - print >>sys.stderr, 'W: message without tickle information: ' + key - move_to_inbox(key) + print >>sys.stderr, 'W: message without tickle information: ' + msgid + resubmit(key) if msgids.get(msgid, None) is None: msgids[msgid] = list() @@ -55,7 +58,7 @@ for msgid, msgs in msgids.iteritems(): t = time.time() if t >= tickle: - move_to_inbox(key) + resubmit(key) else: print >>sys.stdout, 'I: message %s still has %d seconds' % (key, int(tickle - t))