OT: perl mail problems

Da Rock freebsd-questions at herveybayaustralia.com.au
Sun Jan 29 08:15:18 UTC 2012

On 01/29/12 02:13, Matthew Seaman wrote:
> On 28/01/2012 13:39, Da Rock wrote:
>> I know this is not exactly FreeBSD related, but I'm in need of a monk
>> that can enlighten me on a sacred incantation to connect perl to an imap
>> server using Mail::Box modules :) If it helps people sleep, its all
>> running only on FreeBSD systems...
>> I have googled and searched, and googled some more, and tested, and then
>> went back to the drawing board and googled yet again... there is simply
>> no clear answer out there. All the docs are very disjointed from my
>> reckoning- with no clear direction that explains how you get from a-b.
>> I have enabled a connection (I think - based on my tests and logs), but
>> I cannot get further than that. I have a Mail::Box::Manager
>> instantiated, and then I have to use Mail::Box::IMAP4 to open a
>> connection to the server. From there I need to get a list of the folders
>> available- and thats where I get stymied.
>> All the docs are pop3 based, or maildir based, or mbox. The imap is very
>> sketchy... and what is out there says to basically connect, and then
>> there is a jump to folders and messages with no idea of what is involved
>> in between. Although I did see one complete example with pop3, but it
>> won't work for imap.
> This is absolutely typical -- IMAP is frequently treated as
> POP-with-extra-bits, which really makes no sense whatsoever.  There's a
> fundamental difference in behaviour to do with where the mail is
> actually stored.  Anything that works by connecting to an IMAP server
> and downloading all the new messages to hold and read locally really is
> missing the point.
I think there is a genuine effort to help make it easier to use and to 
abstract the backend, but it doesn't seem the coder has a handle on it 
themselves. They seem more familiar with filesystem based mail then the 
network ones- and then familiarity with pop3 rules. Therefore me, as a 
newb, has next to no hope of figuring it out... :/
>> One of the biggest problems is the username confuses any other module
>> method than the Mail::Box::IMAP4 - the syntax is user at domain, and so if
>> I use Mail::Box::Manager it will compile it into a url form ie
>> imap4://user@domain:password@mail.server which it obviously barfs on and
>> refuses to look beyond user at domain.
> Yeah, IMAP4 doesn't do URL-style things itself, so this is a fiction
> invented to appease the higher layers of Mail::Box.  Unfortunately, '@'
> is of syntactic significance to URL schemes, making it difficult to
> incorporate usernames containing it.
> Hmmm.... can you substitute a hex encoded character string in that
> username?  %40 should be the encoding for an @ character.
That could work... I might have a crack at that. I thought pop3 would 
have trouble as well, you can use that username structure there too.
>> I really seem to be missing something fundamental here. I'm only trying
>> to create some tools which will handle some situations apparently only
>> local to my systems, and improve my perl foo before I start creating
>> modules of my own and testing mod_perl.
>> If someone can help clear this up I'll be happy to communicate off list
>> if that is necessary.
> Is all the e-mail you have to deal with stored on your IMAP4 server?  If
> so, then using Mail::IMAPClient directly[*] might serve you better
> rather than through the Mail::Box and Mail::Transport classes.  However,
> that's a much lower level interface and you'll need to be fairly au-fait
> with RFC 3501.  (That's not as bad as it sounds: all it boils down to is
> finding what the command is called in the IMAP protocol when you want to
> achieve a particular effect.)
Yes... I was dreading that a bit, but it does seem easier. I was hoping 
it would be more like Email::Simple, but it doesn't seem to be there 
yet. That said, I'll try that trick and see if it works first.
> One thing that I notice on a cursory reading of Mail::Box::IMAP4 is that
> it seems to assume things about the behaviour of the IMAP message store
> which aren't necessarily true for all different IMAP servers.  (ICBW --
> it was a /very/ cursory reading.)  Usernames of the form
> 'name at example.com' are one of those things you can do with IMAP which
> tend to come as a bit of a surprise to people used to other mailclient
> protocols.
It seems to make some assumptions based on common uses, and I believe it 
said you can override others; but yes it is also "still under 
development" - a note which appears and disappears from time to time :S

Thanks for the help guys. I've stepped away from php for security 
reasons; and the fact that I can integrate perl right into apache with 

More information about the freebsd-questions mailing list