IMAP to Mbox

popowich

EQ Forum Admin
Staff member
IMAPtoMbox.pl

IMAPtoMbox.pl is a utility for extracting all of the mailboxes in an IMAP user's account and writing them to files in the Unix mbx format.

The user supplies host/user/password information and the name of a directory on the local system. IMAPtoMbox.pl connects to the IMAP server and extracts each message in the user's IMAP mailboxes. Those messages are written to a file with the same name as the IMAP mailbox into the specified directory.

For example:

./IMAPtoMbox.pl -i localhost/rfs/mypass -m /var/rfs

Optional arguments:
-d debug
-L logfile
-M IMAP mailbox list (dumps the specified mailboxes, see the usage notes for syntax)
If you have a question about using this script please reply.

If you would like to download the script please see How to get the IMAP Tools.
 

popowich

EQ Forum Admin
Staff member
I'm working with the IMAP to mbox right now and sometimes (not always) it stops with the error message:

The 'hour' parameter (undef) to DateTime::new was an 'undef', which is not one of the allowed types: scalar
at /usr/lib64/perl5/vendor_perl/DateTime.pm line 176
DateTime::new(undef, 'second', 0, 'minute', undef, 'hour', undef, 'day', undef, ...) called at /usr/local/imap-tools/IMAPtoMbox.pl line 618
main::getMsgList('INBOX', 'ARRAY(0x1a063f0)', 'IO::Socket::INET=GLOB(0x207e288)') called at /usr/local/imap-tools/IMAPtoMbox.pl line 57

It's using the same hosting as a source that you were testing as the destination for imapcopy.pl
 

rfs9999

IMAP Tools
Apparently the date in the message that IMAPtoMbox is trying to convert to a Rfc822 date is formatted badly. Can you get me a copy of the message so I can see what the problem is?

-Rick
 

rfs9999

IMAP Tools
The date is a bit odd (Date: Thu, 24 May 2018 05:23:27 +0800) but it didn't cause an error when I ran IMAPtoMbox on it. Is it 2018 already? I must have overslept. :)

Turn on debug (-d and -I) and let's see what the log shows. Should be something like this:

<< * 2 FETCH (UID 2 FLAGS (\Recent) INTERNALDATE "23-May-2018 21:23:27 +0000" BODY[header.fields ("From" "Date")] {94}
<< From: =?utf-8?B?5L6v6K+a5Yqb?= <ijsee@iauctb.ac.ir>
<< Date: Thu, 24 May 2018 05:23:27 +0800

-Rick
 

popowich

EQ Forum Admin
Staff member
It was getting through a lot of emails before the error, it's not the first message.

I replaced a spammer domain with example.com

Here is the end of the debug output:

<< * 13786 FETCH (UID 13786 FLAGS () INTERNALDATE "21-Feb-2014 13:11:38 +0000" BODY[HEADER.FIELDS (FROM DATE)] {116}
<< Date: Fri, 21 Feb 2014 13:00:31 +0000 (GMT)
<< From: Home Media Magazine <HomeMediaDaily@example.com>
<<
<< )
<< 1 OK Fetch completed.
badly formatted date in message: , 23 Dec 2007 22:42:15 +0800
calculated replacement date as: Sun Dec 23 22:42:15 2007
badly formatted date in message: , 23 Dec 2007 18:53:15 +0200
calculated replacement date as: Sun Dec 23 18:53:15 2007
The 'hour' parameter (undef) to DateTime::new was an 'undef', which is not one of the allowed types: scalar
at /usr/lib64/perl5/vendor_perl/DateTime.pm line 176
DateTime::new(undef, 'second', 0, 'minute', undef, 'hour', undef, 'day', undef, ...) called at /usr/local/imap-tools/IMAPtoMbox.pl line 618
main::getMsgList('INBOX', 'ARRAY(0x1aee5d0)', 'IO::Socket::INET=GLOB(0x2166678)') called at /usr/local/imap-tools/IMAPtoMbox.pl line 57
 

rfs9999

IMAP Tools
I'm not able to reproduce the error using ", 23 Dec 2007 22:42:15 +0800" for the date from the message:

date: , 23 Dec 2007 22:42:15 +0800
newdate Sun Dec 23 22:42:15 2007
badly formatted date in message: , 23 Dec 2007 22:42:15 +0800
calculated replacement date as: Sun Dec 23 22:42:15 2007
date Sun Dec 23 22:42:15 2007

-Rick
 

popowich

EQ Forum Admin
Staff member
Hi Rick,

I sent the complete email. It appears to be a malformed spam.

It's probably worth being able to not error on them though.

Since it's a spam it may have gone to your spam folder.
 

rfs9999

IMAP Tools
I have released a new version of IMAPtoMbox with a fix for the bad-date problem. Now instead of dying if a message has a date that cannot be parsed IMAPtoMbox inserts the current date and continues.

-Rick
 

popowich

EQ Forum Admin
Staff member
The date Tue Mar 25 15:29:28 2008 is badly formatted, using today's date instead

Looks good, it's not stopping with an error because of malformed spam emails anymore.

BTW, I was looking at this while I was working on using Outlook + IMAP to create some backups to PST files

An "IMAP to PST" would have made life easier. :)
 

rfs9999

IMAP Tools
I've looked at building imap_to_pst in the past. The stumbling block has always been finding a reliable tool for creating the PST file. Microsoft doesn't exactly make it easy.

I am looking at a product from Bitdaddy (Open email files. .msg .pst .emlx and .eml View, Convert, Extract, Search, Print) which I just used to create a small PST file from several .eml files.

I don't have Outlook here to test the resulting PST file so I sent it to you. Please give it a try and let me know how it looks.

Another obstacle is that most products like this one are GUI-based and don't provide a command-line mode that permits integration with one of my IMAP tools.

-Rick
 
Top