Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

I need some help doing the following:

Connecting to a server using POP3, and that server in return will connect to another server that uses IMAP

Meaning (Me -> Server in the middle -> IMAP Server )

the server in the middle will act as a proxy translating pop3 command into imap and vice versa.

Anybody can help?

Replies are listed 'Best First'.
Re: IMAP to POP3 Proxy
by Sewi (Friar) on Sep 04, 2009 at 07:00 UTC
    There are situations where uncommon things like this are neccessary.
    You'll loose a great amount of IMAP-features like folders and server-stored postbox, but many mailservers and clients don't use them anyway.
    At first, you should look at CPAN (www.cpan.org) for POP3 and IMAP modules.

    Net::Server::POP3 seems to be a good choice. You could define subs for each POP3 action and the whole protocol is done by the module.

    Net::IMAP::simple is a good choice for the client side. It offers only few IMAP-commands, but all you need is list, read and delete mails and this should be easy as this module is well documentated and there are good samples.

    You won't get the source for the whole proxy server here, but the modules are a good way to start and feel free to come back if you got any questions.

    PS: I think this script would be a nice sample for the Cool uses for Perl section on this site.

Re: IMAP to POP3 Proxy
by afoken (Chancellor) on Sep 04, 2009 at 05:09 UTC

    Are you aware of the differences between POP3 and IMAP? The most trivial difference is that POP3 gives you read-and-maybe-delete access to exactly one mailbox directory (commonly called INBOX), whereas IMAP gives yo access to all mailbox directories and even allowes you uploads (yes, one can abuse IMAP to replace SMTP). Your proxy would allow you to access only one of the mailbox directories, and it would not allow you anything but reading and deleting.

    Connect via IMAP. There is no reason to use POP3.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Yes actually, There are some situation where you find it required!

      What happened exactly is like the following.

      My university give us mailbox with 70 MBytes only so I used to fetch emails through gmail pop3 fetch.

      And Delete the emails from the university Mail box, So far in 1 year I've used like a 1 GB of disk space in Gmail.

      Today, The university techs have removed the POP3 and allows only IMAP (which is not supported by Gmail fetch functionality).

      My only thought was to make a proxy, run it on a development box I have, and use it to fetch my university emails through gmail.

      Sounds complicated, but possible

        Configure the university mail account to forward your mails to your gmail account. No need to fiddle with proxies. If the university uses a unix system with sendmail or compatible systems, just create a file named ".forward" in your home directory containing your gmail address (i.e. echo 'anonymous_monk@gmail.com' > $HOME/.forward). For other mail servers, there are similar mechanisms. For Exchange / Outlook, you have to move your mouse for a while, digging through the Outlook menus that change with every new version. Just ask the mailserver admins or the hotline for help.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)