[PATCH 1/4] Re: Simplify & document savemessage_getnewheader

Nicolas Sebrecht nicolas.s-dev at laposte.net
Fri Jan 21 20:24:27 UTC 2011


On Fri, Jan 21, 2011 at 03:09:04PM +0100, Sebastian Spaeth wrote:
> 
> savemessage_getnewheader was an undocmented, cryptic and overengineered
> function. It generates a new unique value that can be used as a mail
> header to be inserted. For this it used LOTS of randomness sources: hash
> of the mail content, hash of the folder name, hash of the repository
> name, the current time, a random() value, and the offlineimap version string.
> All we need is something random. So reduce this to hash of content
> appended by a random integer. Sufficient and somewhat faster to calculate.
> 
> Rename the function to actually describe accurately what it does or
> would you have guessed that savemessage_getnewheader() did nothing more
> than returning ('X-OfllineIMAP', <randomstring> )? Rename to
> generate_randomheader() to make it clearer what this is all about.
> 
> Also document the function, describing what it does, and what it returns.
> 
> Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
> ---
>  offlineimap/folder/IMAP.py |   26 ++++++++++++++++++--------
>  1 files changed, 18 insertions(+), 8 deletions(-)

I was first sceptical to see more insertions than deletions for
something pretending to bail out overengineered stuff but it comes from
the added documentation.

I would add a comment in the code about the importance of the random()
part of the number which avoid possible collisions against a "hash
content only" strategy, though.

-- 
Nicolas Sebrecht



More information about the OfflineIMAP-project mailing list