rjbs / Email-MIME

perl library for parsing MIME messages
20 stars 30 forks source link

Method filename is not stable #46

Open pali opened 7 years ago

pali commented 7 years ago

Method invent_filename is used by method filename which returns suggested file name.

But invent_filename uses module global variable counter which is appended into returned file name. Therefore method filename is not stable as documented in Email::MIME documentation and depends on order of Email::MIME objects on which were invent_filename resp. filename called.

MIME email is tree structure and every vertex is MIME part on which can be called invent_filename method. Therefore stable implementation of invent_filename method must uniquely encode vertex in the tree. MIME email is rooted tree, so vertex can be encoded by just the path from root.

pali commented 7 years ago

Other option is to order all MIME parts (vertices of rooted tree) by some stable algorithm and assign index in ordered list. The most common usage is invent filename for just for leafs, so ordering could start from bottom leafs up to root vertex, to have only small numbers used in invented files for most cases.