On Thu 2020-01-23 12:51:47 -0700, Sean Whitton wrote: > I just discovered that it is possible to implement imap-dl using the > Mail::Box suite. This would mean we would not need to include any code > parsing and emitting the IMAP protocol in mailscripts. That seems > strongly preferable. Let me know what you think. > > Here is what the fetch code becomes: > > #!/usr/bin/perl > > use 5.028; > use strict; > use warnings; > > use Mail::Box::Manager; > > my $mgr = Mail::Box::Manager->new; > my $imap_folder = $mgr->open('imap://user:passwd@host:port/INBOX'); > my $maildir = $mgr->open( > '/home/spwhitton/Maildir', > access => 'a', > create => 1, > keep_dups => 1, > type => 'maildir' > ); > $mgr->moveMessage($maildir, $_) for $imap_folder->messages(); > $mgr->closeAllFolders(); > > We could even keep all dkg's existing code for parsing getmail configs, > etc., and use Mail::Box only to do the actual fetch and insert.
If you want to do this in perl, you're welcome to. I won't be able to help much in maintaining it, though, as my perl is super weak, and i have to thrash around a lot just to test things and make sure that they're doing what i expect them to do. In contrast, i find python to be cleaner and simpler to understand an to annotate. I'm also not convinced that the above code enforces tls, checks certificates, etc. Also, have you compared the speed of the above code against the current python implementation when fetching an off-site mailbox with some noticeable latency and a decent-sized spool? I found that imap-dl is several orders of magnitude faster than getmail, because it avoids additional roundtrips based on its deliberate use of the IMAP protocol. I don't know whether that's the case for Mail::Box (i haven't tested!) but i would be pretty sad to go back to waiting dozens of seconds to fetch hundreds of messages that could be fetched instead in a couple seconds. --dkg
signature.asc
Description: PGP signature