IMAP Sync

popowich

EQ Forum Admin
Staff member
imapsync.pl

imapsync is a utility for synchronizing a user's account on two IMAP servers. When supplied with host/user/password information for two IMAP hosts imapsync does the following:

1. Adds any messages on the 1st host which aren't on the 2nd
2. Deletes any messages from the 2nd which aren't on the 1st
3. Sets the message flags on the 2nd to match the 1st's flags

imapsync is called like this:

single user:

./imapsync -S host1/user1/password1 -D host2/user2/password2

multiple users:

./imapsync -S host1 -D host2 -u <users file>

Optional arguments:
-d debug
-u <users file> src_user:src_pwd:dst_user:dst_pwd
-L logfile
-m mailbox list (sync only certain mailboxes,see usage notes)
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
Hi Rick,

What do you think about adding a quiet mode to imapsync.pl?

If I don't specify -L <logfile> I get A LOT of error messages while the sync is running.

There are so many so fast that it's impossible to read them real time.

Some examples of the error messages are Permission Denied from the source server.

If I specify -L <logfile> then I don't get any output and everything goes to the log file.

What I would like is a combination of options that lets me both log everything but also have successful progress "status" messages displayed on my screen as it's moving through the list of users letting me know how many messages have been moved etc.

10-28-2013.14:26:59 13515 Added 0
10-28-2013.14:26:59 13515 Updated 0
10-28-2013.14:26:59 13515 Deleted 0
10-28-2013.14:26:59 13515 Connected to x.x.x.x on port 143
10-28-2013.14:26:59 13515 Authenticating as username@example.com
10-28-2013.14:26:59 13515 Connected to 127.0.0.1 on port 143
10-28-2013.14:26:59 13515 Authenticating as username@example.com
10-28-2013.14:26:59 13515 There are 116 mailboxes to sync

I could tail -f the log file and | grep -v the noisy patterns, but it would be cleaner if I could run imapsync.pl with a -q (quiet) flag that suppresses most errors and maybe let me -L logfile in addition to getting progress displayed.
 

rfs9999

IMAP Tools
Ray,

> What I would like is a combination of options that lets me both log everything but also have successful progress "status" messages displayed on my screen as it's moving through the list of users letting me know how many messages have been moved

Sounds like a good idea. I'll work on it.

-Rick
 

rfs9999

IMAP Tools
Quiet mode has been added to imapsync.pl. You put it into quiet mode by adding -q to the command line. Here's what the output looks like:

Attempting a non-SSL connection
Connected to localhost on port 1430
Authenticating as <source user>
Logged in as <source user>
Connected to localhost on port 9930
Authenticating as <dest user>
Logged in as <dest user>
There are 1 mailboxes to sync
Checking for adds & updates
Inbox has 509 messages
Added 10 messages to Inbox
Deleted 12 messages from Inbox

Summary of results
Added 10
Updated 0
Deleted 12

Ray, I'll send you the new version.

-Rick
 

DasBill

New Email
Hello,

how i can force SSL?

The script returns the following error:

"unexpected LOGIN response: 1 NO [PRIVACYREQU
lowed on non-secure (SSL/TLS) connections."
 

rfs9999

IMAP Tools
>How can I force SSL?

Add :993 to the host name. For example: -S imap.gmail.com:993

This works on all of the IMAP tools.

-Rick
 

DasBill

New Email
>How can I force SSL?

Add :993 to the host name. For example: -S imap.gmail.com:993

This works on all of the IMAP tools.

-Rick

Thanks for the quick support.

Apparently the script has problems with special characters like "/" or "=" to deal
what could one do?

I have the password already set in quotation marks.

(Sorry for my bad english)
 

rfs9999

IMAP Tools
>Apparently the script has problems with special characters like "/" or "=" to deal what could one do? I have the password already set in quotation marks.

If the username or password has a '/' and you are supplying them on the command line the problem is that imapsync expects the host, user, and password to be delimited by '/'.

-S host/user/password

To get around that put the names and passwords into a file and tell imapsync to use it with -u <file>

-S host -u users.dat

Create a file (users.dat):

source_user:source_password:destination_user:destination_password

(If this is an unacceptable workaround please contact me directly at rfs9999@earthlink.net and I will send you a new version that lets you use '\' as the delimiter instead of '/').

Other special characters like ?, !, and $ will probably cause problems for the shell interpreter. They should be delimited with a backslash:

\?
\!
\$

That tells the shell to treat them as regular characters not special ones.

-Rick
 

rfs9999

IMAP Tools
Here is how you delimit the values in the new version using the backslash instead of the forward slash:

-S host\\jessi\\password -D host\\chuy\\password

Note that you have to delimit the backslash to tell the shell not to interpret \ as a special character.

The new version is available now.

-Rick
 
Top