apache / incubator-ponymail-foal

Apache Pony Mail Foal (Next Generation Suite)
https://ponymail.apache.org
Apache License 2.0
23 stars 14 forks source link

Use email.headerregistry classes? #162

Open sebbASF opened 2 years ago

sebbASF commented 2 years ago

The headerregistry classes [1] look useful for parsing, especially for address types which are rather complicated.

In particular the AddressHeader handles multiple addresses, and splits the address into display and email.

MessageID was added in 3.8, but does not trim leading spaces. That is trivial to fix.

[1] https://docs.python.org/3.7/library/email.headerregistry.html

sebbASF commented 2 years ago

It looks like policy=compat32 does not use the headerregistry, so this would need to be taken into account if the option is to be kept.

sebbASF commented 2 years ago

Note: unless the compat32 policy is used, the values returned from msg.get() are already instances of BaseHeader.

However the code does not yet use the additional features. For example one can do something like this:

if isinstance(val, email.headerregistry.AddressHeader):
    msg_metadata[key] = []
    for addr in val.addresses:
        msg_metadata[key].append(str(addr))
sebbASF commented 2 years ago

Further experimentation shows that the new policies are stricter when parsing headers. This could be a problem, especially when importing older emails.

It will be difficult to maintain compatibility with earlier versions and with mod_mbox. This is especially true of Message-ID and References (though the latter does not yet have a header parser). It might be necessary to override the parsers for these headers