No matters your religion, IMAP4 or HTTP, you should not worry about accessing easily header and associated attributes, adjectives or values.
But even with modern language like Python we still have those :
charset = headers['Content-Type'].split(';')[-1].split('=')[-1]
I have seen so much chunk of code like this, trying to deal with them, often in a risky way to take care of a more important part of the code. In the face of that I say no more!
Do not forget that headers are not OneToOne. One header can be repeated multiple times and attributes can have multiple values within the same header. So representing them by using a
is not a good idea even if using case insensible dict !
charset = headers.content_type.charset # better now ?
Kiss-Headers is a library that allows you to handle with great care headers.
That is why I created a project that would remove the pain of dealing with them no matter where they came from.
It was clear that they were something missing in the python community. From the project
, each one has its implementation, each one is also incomplete. The best so far I have seen is the one from
Mine is not perfect but has its amount of sweetness. Beginning from auto-completion capability in python interpreter or your beloved IDE. It should dramatically reduce stress and pain when encountering them.
Plus all the features that you would expect from handling headers...
Imagine being capable of doing those things :
Repository : https://github.com/Ousret/kiss-headers
I am pretty confident that those kinds of libraries that serve reducing time spent on the little things would actually help make the life of a programmer easier. And spent a lot more time on something else.
So, do not hesitate, when you are encountering a case that respects those criteria : (i) repeatably reinventing the wheel (ii) everyone is facing this issue at least once. (iii) break the loop by contributing.
Thank you :)