Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Thread-safe SSL IMAP

by gxbacher (Novice)
on Sep 21, 2011 at 16:37 UTC ( #927177=perlquestion: print w/replies, xml ) Need Help??
gxbacher has asked for the wisdom of the Perl Monks concerning the following question:

I've run into problems (on Windows) using Mail::IMAPClient and Net::IMAP::Simple::SSL because IO-Socket-SSL isn't thread-safe. Does anybody know of a Perl IMAP module that is SSL-capable and doesn't use IO-Socket-SSL? Or how about a drop-in replacement for IO-Socket-SSL that is thread-safe? Thanks!

Replies are listed 'Best First'.
Re: Thread-safe SSL IMAP
by onelesd (Pilgrim) on Sep 21, 2011 at 17:39 UTC

    See this thread for a similar case.

    I ended up isolating the SSL bits of code in a separate script, and using bi-di IPC (see: IPC::Open2) to circumvent the issue of Crypt::SSLeay not being thread-safe. If you don't need bi-di communication, just use perl's open.

Re: Thread-safe SSL IMAP
by Anonymous Monk on Sep 21, 2011 at 16:57 UTC
    Then thread-safety isn't such a big deal if you do it like
    my $safeIfTheOnlyOne = threads->create('oneAndOnlyMailer', 'argument') +; sub oneAndOnlyMailer { require IO::Socket::SSL; require Mail::IMAPClient ; require Net::IMAP::Simple::SSL; ... }

    If you need multiple mailers, then it would pay to make IO::Socket::SSL thread-safe

Re: Thread-safe SSL IMAP
by Corion (Pope) on Sep 22, 2011 at 07:12 UTC

    If you need to multiplex more than one IMAP connection, or do some fake "multiple email" thing, it might be worth it to look into AnyEvent::TLS, which provides SSL sockets for AnyEvent and potentially Net::Async::IMAP::Client, which seems to be based on IO::Async, which works with AnyEvent.

Re: Thread-safe SSL IMAP
by gxbacher (Novice) on Jan 26, 2012 at 15:52 UTC

    Thanks for all the suggestions. Since I'm stuck on Windows, I ended up creating separate processes instead of threads or using forking.

    I'm using Win32::Process to kick off my "children", and that returns an object I can use to manage them if they go astray.

    I'm using Win32::MMF for shared memory, sort of.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://927177]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-05-21 16:07 GMT
Find Nodes?
    Voting Booth?