lefcha / imapfilter

IMAP mail filtering utility
MIT License
850 stars 93 forks source link

Excluding messages that have a particular flag isn't working #69

Closed rightaway closed 10 years ago

rightaway commented 10 years ago

I'm getting the following error on the console when trying to use a minus sign to exclude some mails that have a particular flag set:

imapfilter: IMAP (3): 1029 BAD parse error: zero-length content

And what ends up happening in this example is that messages with the the $label4 flag set (this is a Thunderbird flag) don't end up getting excluded from the condition, so they are marked as seen when they shouldn't be.

    res = (mymail.Inbox:contain_from('address1@example.com')
          + mymail.Inbox:contain_cc('address2@example.com'))
          - mymail.Inbox:has_flag('$label4')
    res:mark_seen()

If I remove the condition with the minus sign (remove the 3rd line from the above), then I don't get the parse error.

The only thing I can imagine I'm doing wrong is that it's in an earlier condition in the same config.lua where I add the flag $label4, and just a few lines down is where I check for that same flag. Maybe I need to run some other command before doing the has_flag check in order for imapfilter to pick up the addition of the flag to those messages?

(Or maybe it's a problem with the way I've written it out, as I'm brand new to Lua.)

lefcha commented 10 years ago

The problem doesn't seem to be with the '-' minus sign, but the server doesn't seem to like the $label4 flag you are trying to check. In my test IMAP server, searching for this flag seems to work ok.

To be sure you can run imapfilter with: imapfilter -d debug.log and then try to find the request sent to the server (just before this BAD error response you get). You can then copy/paste that part here.

Also, when you set this flag, does everything go well, or do you get some error there, too? You can also check that in the debug.log output.

rightaway commented 10 years ago

This is the problematic one, near the end of the log:

sending command (4):

102C UID SEARCH ALL KEYWORD "$label4"

getting response (4):

102C BAD parse error: zero-length content

And these are all the other parts of my log related to $label4 (they all appear in the log before the entries above). This is where I'm setting the flags:

1005 SELECT "Inbox"

getting response (4):

* 244 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UIDs are valid for this mailbox
* OK [UIDNEXT 60711] next expected UID is 60711
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk $label4 Later)
* OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $label4 Later \*)] junk-related flags are not permanent
* OK [HIGHESTMODSEQ 261025] modseq tracked on this mailbox
1005 OK [READ-WRITE] SELECT completed

sending command (4):

1006 UID SEARCH ALL FROM "address@example.com"

getting response (4):

* SEARCH
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk $label4 Later)
1006 OK UID SEARCH completed
sending command (4):

1015 UID STORE 7374,25933,28043,28068,28073,28135:28136,29077,29196,29198,29319,29331,29531,31457,47912,48231,49012,49414,49563,49732,49766,49856:49857,49877,50204,50224:50225,50249,50257,50266:50267,50274:50275,51308,51329:51330,51569,51652,51759,51850,51950,52090,52111,52143,52145,52147:52148,52219,52388,52812,53061,53463,53470,54157,54382,54536,54578 +FLAGS.SILENT ($label4)

getting response (4):

1015 OK UID STORE completed

sending command (4):

1016 UID STORE 54584,54714,54851,54973,54982:54983,55224:55225,55277,55335,55416,55475:55476,55506,55518,55855,55878,56049:56050,56151,56156,56198:56200,56203,56234,56239:56240,56243,56374,56384,56393,56402,56430,56523,56578,56581,56600,56630,56677,56682,56708:56710,56714,56717:56719,56749,56811,56814,56817,56978,56996,57030,57222,57275,57422,57529,57541,57548 +FLAGS.SILENT ($label4)

getting response (4):

1016 OK UID STORE completed

sending command (4):

1017 UID STORE 57571,57575,57617:57618,57624,57636,57742,57764,57838,57910,57916,57922,57927:57928,58921,58935,59147,59296,59382,59384:59386,59704,59764,59774,59822,59830,59834:59836,59855,59860,59871,59876:59878,59949,60070,60220,60224:60225,60331,60347,60351,60354:60355,60358,60382,60432,60501,60533,60566,60581:60582 +FLAGS.SILENT ($label4)

getting response (4):

1017 OK UID STORE completed
rightaway commented 10 years ago

I've got some more information. It's not just that it doesn't like the $label4 flag, it doesn't seem to like searching for any flag. But the strangest part is it has no problem adding flags. The following works fine and the flags appear in another mail client:

results:add_flags({ '$label4' })

By the way, my IMAP server is a relatively recent version of Zimbra.

Here are other examples of the errors. If I make my config.lua very minimal, having pretty much only this, it still gives the same error:

mymail.Inbox:has_flag('$label4')

But even if I take out the dollar sign it doesn't make a difference:

mymail.Inbox:has_flag('nonexistingtag')

And it doesn't have to do with the tag existing or not, because if I create 'existingtag' in another mail client then run the following, I get the same error:

mymail.Inbox:has_flag('existingtag')
lefcha commented 10 years ago

This looks like the server has some issue searching with the KEYWORD argument. I just tried on my test server and it works fine both adding the $label4 flag, and also searching for it with ALL KEYWORD "$label4". Maybe it's the configuration of the server, or some functionality missing, or a bug...