imh

Check-in [b658d08d61]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fail back to "now" on un-parseable header date/time
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:b658d08d61205188308a46ebd7c0ac48f9b047f56307ee4e3bfc166f11edc69a
User & Date: ajv-899-334-8894@vsta.org 2016-11-22 22:19:02
Context
2016-11-26
22:57
maplib2 doesn't like utf hostnames check-in: 5b2bc8a217 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-22
22:19
Fail back to "now" on un-parseable header date/time check-in: b658d08d61 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-21
01:02
Defend against non-ASCII input check-in: e2b80c29fe user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to imh.py.

426
427
428
429
430
431
432


433
434



435
436
437
438
439
440
441
442
443
444
445
446
447
448





449
450
451
452
453
454
455
        for f in flags.split():
            res.add(f[1:])

        return res

    # Parse an email Date: field as a timeval
    def dt_parse(self, t):


        tup = t.split()
        base = " ".join(tup[:5])



        tm = time.strptime(base, "%a, %d %b %Y %H:%M:%S")
        tmf = time.mktime(tm)
        hrs = tup[5]
        if hrs[0].isalpha():
            # TBD, decode timezone name like "EST" and get
            #  an offset.  But standard Python doesn't
            #  appear to have this?!?
            pass
        else:
            deltaval = 60*60*int(hrs[1:3]) + 60*int(hrs[3:5])
            if hrs.startswith('+'):
                tmf += deltaval
            elif hrs.startswith('-'):
                tmf -= deltaval





        return time.localtime(tmf)

    # Parse a BODYSTRUCTURE hierarchy
    def parse_body(self, s):
        return BodyParser(s).parse()

    # Accept text as in "Cc: <addrs...>", and return the







>
>


>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
        for f in flags.split():
            res.add(f[1:])

        return res

    # Parse an email Date: field as a timeval
    def dt_parse(self, t):

        # Normalize whitespace
        tup = t.split()
        base = " ".join(tup[:5])

        # Try to interpret by the RFC
        try:
            tm = time.strptime(base, "%a, %d %b %Y %H:%M:%S")
            tmf = time.mktime(tm)
            hrs = tup[5]
            if hrs[0].isalpha():
                # TBD, decode timezone name like "EST" and get
                #  an offset.  But standard Python doesn't
                #  appear to have this?!?
                pass
            else:
                deltaval = 60*60*int(hrs[1:3]) + 60*int(hrs[3:5])
                if hrs.startswith('+'):
                    tmf += deltaval
                elif hrs.startswith('-'):
                    tmf -= deltaval

        # Just sigh and use "now" if it's malformed
        except:
            tmf = time.time()

        return time.localtime(tmf)

    # Parse a BODYSTRUCTURE hierarchy
    def parse_body(self, s):
        return BodyParser(s).parse()

    # Accept text as in "Cc: <addrs...>", and return the