in reply to Get CID inline attachments with MIME::Parser
Scary.
The whole idea of bypassing conventional e-mail handling looks just wrong.
I think you should have a look at IMAP::Client. Did you know that you can very efficently fetch just the headers of an e-mail via IMAP? This is optimal for a webmailer when you want to show the contents of a mailbox. Simply because you do less work for the same result. So, you should really use IMAP to access the e-mails.
Access via IMAP also allows you to cleanly separate mail server and webmail. It allows you to switch mail servers without having to touch a single bit of your webmailer code. You can even use your webmailer to access several different IMAP servers in parallel.
I think that you should run MIME::Parser only on demand, i.e. when displaying a mail in your webmailer. You could add a caching layer (i.e. inherit from MIME::Parser and add caching logic) that avoids calling MIME::Parser more than once for any given e-mail, storing not only the attachments, but the entire state of MIME::Parser into a (set of) files in a directory accessible only to the owner of the mail. Find out if Storable, Data::Dumper, or some other class can help you serialising and unserialising MIME::Parser objects. Benchmark that! The native e-mail format serialises the same data, and perhaps it is faster to have MIME::Parser parse that format again than to reconstruct a MIME::Parser object from Storable or Data::Dumper.
Sure, running MIME::Parser inside the webmailer slows down the webmailer. Benchmark how much it will slow down. With typical small mails (less than 1 MByte), I would bet that MIME::Parser is so fast that you won't notice any delay at all. For larger mails, do what others to when the user has to wait for a long-running action: Show an animation. In a web mailer, you would typically use an animated GIF, using a little bit of JS and CSS to show it overlaying the current page immediately before the mail view page is loaded. It doesn't speed up things, but makes your users more patient.
If you really, really want to avoid IMAP at all costs, have a look at maildir, maildir++, and IMAPdir. They give you an instant "one e-mail == one file" solution, with no need for locking, and with unique file names. You can use the file name, minus the info (flags) part, as a key for caching already-processed e-mails.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get CID inline attachments with MIME::Parser
by sebastiannielsen (Initiate) on Nov 28, 2010 at 20:58 UTC | |
by roboticus (Chancellor) on Nov 28, 2010 at 21:17 UTC | |
by Marshall (Canon) on Nov 28, 2010 at 23:24 UTC | |
by afoken (Chancellor) on Nov 29, 2010 at 13:35 UTC |