jvc / cleanup-maildir

cleanup-maildir python script that works with python 2.4 and >=2.5
19 stars 13 forks source link

HeaderParseError #1

Closed jasonblewis closed 13 years ago

jasonblewis commented 13 years ago

Hi,

I'm having this problem with cleanup-maildir when i run it on a large folder of mail, i get this error:

Traceback (most recent call last): File "./cleanup-maildir", line 504, in cleaner.clean(mode, dir, minAge) File "./cleanup-maildir", line 405, in clean self.log(logging.DEBUG, "Keeping #%d (fresh)" % i, msg) File "./cleanup-maildir", line 410, in log subj = msgObj.getSubject() File "./cleanup-maildir", line 209, in getSubject email.Header.decode_header(s))) File "/usr/lib/python2.6/email/header.py", line 101, in decode_header raise HeaderParseError email.errors.HeaderParseError

i added some debug code, to try and get more info, but I'm no expert in python so i'm a bit lost as to how i might get more info.

i changed the code to read: def getSubject(self): """get the message's subject as a unicode string"""

    import email.Header
    s = self.getheader("Subject")
    try:
        print "DEBUG: subject=", s
        return u"".join(map(lambda x: x[0].decode(x[1] or 'ASCII', 'replace'),
                            email.Header.decode_header(s)))
    except(LookupError):
        return s
    except:
        print "Unexpected error:", sys.exc_info()[0]
        print "email.Header.decode_header(s) s =", s
        raise

also note - here is my debug output INFO:MaildirCleaner:(Not really) Archiving #18127 to a Reference.2007: TCF: UNS: Segfault in Samba DEBUG: subject= eBay Favourite Search: m-audio INFO:MaildirCleaner:(Not really) Archiving #18128 to a Reference.2007: eBay Favourite Search: m-audio DEBUG: subject= Updated barcodes showing essdale park counter stand with barcode DEBUG: subject= =?UTF-8?B?VGhhbmsgeW91IGZvciB5b3VyIGZlZWRi?==?UTF-8?B?YWNr?= Unexpected error: <class 'email.errors.HeaderParseError'> email.Header.decode_header(s) s = =?UTF-8?B?VGhhbmsgeW91IGZvciB5b3VyIGZlZWRi?==?UTF-8?B?YWNr?=

see how the header is funny for the last one that seems to cause the error?

any suggestions?

Jason

jasonblewis commented 13 years ago

I tracked down the bug to an issue with how unicode subjects are encoded sometimes incorrectly by mail agents.

see the discussion here: http://bugs.python.org/issue10574#msg122776

ill post a patch shortly

jpforte commented 9 years ago

I am having this problem. Any update?

jvc commented 9 years ago

Sorry.. I don't have any updates and haven't used it in a few years. On Dec 12, 2014 6:58 AM, "jpforte" notifications@github.com wrote:

I am having this problem. Any update?

— Reply to this email directly or view it on GitHub https://github.com/jvc/cleanup-maildir/issues/1#issuecomment-66764132.

jpforte commented 9 years ago

Ahh too bad it's a great utility

Jim Forte MAGNA Timeshare Software Magna VEGA, (vacation equities) 407-352-2402,5050 Http://www.magna.net Mailto:james@Magna.Net Sent from my iPhone

On Dec 12, 2014, at 8:33 AM, Justin Chouinard notifications@github.com wrote:

Sorry.. I don't have any updates and haven't used it in a few years. On Dec 12, 2014 6:58 AM, "jpforte" notifications@github.com wrote:

I am having this problem. Any update?

— Reply to this email directly or view it on GitHub https://github.com/jvc/cleanup-maildir/issues/1#issuecomment-66764132.

— Reply to this email directly or view it on GitHub.

jvc commented 9 years ago

You might try using a mail client to move the message that the script is having a problem with. On Dec 12, 2014 8:45 AM, "jpforte" notifications@github.com wrote:

Ahh too bad it's a great utility

Jim Forte MAGNA Timeshare Software Magna VEGA, (vacation equities) 407-352-2402,5050 Http://www.magna.net Mailto:james@Magna.Net Sent from my iPhone

On Dec 12, 2014, at 8:33 AM, Justin Chouinard notifications@github.com wrote:

Sorry.. I don't have any updates and haven't used it in a few years. On Dec 12, 2014 6:58 AM, "jpforte" notifications@github.com wrote:

I am having this problem. Any update?

— Reply to this email directly or view it on GitHub https://github.com/jvc/cleanup-maildir/issues/1#issuecomment-66764132.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/jvc/cleanup-maildir/issues/1#issuecomment-66773983.