1
0
mirror of https://github.com/imapsync/imapsync.git synced 2024-11-17 08:12:48 +01:00
imapsync/doc/TUTORIAL_Unix.html

487 lines
15 KiB
HTML
Raw Normal View History

2016-01-22 17:52:28 +01:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META NAME="generator" CONTENT="http://txt2tags.org">
<TITLE>Imapsync tutorial</TITLE>
</HEAD><BODY BGCOLOR="white" TEXT="black">
<CENTER>
<H1>Imapsync tutorial</H1>
2018-05-07 16:04:23 +02:00
<FONT SIZE="4"><I>Gilles LAMIRAL gilles@lamiral.info</I></FONT><BR>
<FONT SIZE="4">$Id: TUTORIAL_Unix.t2t,v 1.25 2018/05/05 22:39:12 gilles Exp gilles $ </FONT>
2016-01-22 17:52:28 +01:00
</CENTER>
<P></P>
<HR NOSHADE SIZE=1>
<P></P>
<UL>
2017-09-23 23:54:48 +02:00
<LI><A HREF="#toc1">1. Good practices overview</A>
2016-01-22 17:52:28 +01:00
<LI><A HREF="#toc2">2. Basic steps</A>
<UL>
<LI><A HREF="#toc3">2.1. Verifying imapsync works well on its own</A>
<LI><A HREF="#toc4">2.2. Working with your data</A>
<LI><A HREF="#toc5">2.3. Prepare your credentials</A>
<LI><A HREF="#toc6">2.4. Take a real user account as source</A>
<LI><A HREF="#toc7">2.5. Take a test user account as destination</A>
2016-09-19 17:15:41 +02:00
<LI><A HREF="#toc8">2.6. Edit your own script mysync</A>
2016-01-22 17:52:28 +01:00
</UL>
2016-09-19 17:15:41 +02:00
<LI><A HREF="#toc9">3. Background knowledge about emailboxes</A>
2017-09-23 23:54:48 +02:00
<LI><A HREF="#toc10">4. Imapsync presentation</A>
<LI><A HREF="#toc11">5. Conventions</A>
<LI><A HREF="#toc12">6. Why start with a test account on destination host2?</A>
2018-05-07 16:04:23 +02:00
<LI><A HREF="#toc13">7. Imapsync default behavior</A>
2017-09-23 23:54:48 +02:00
<LI><A HREF="#toc14">8. To go further with imapsync</A>
2016-01-22 17:52:28 +01:00
</UL>
<P></P>
<HR NOSHADE SIZE=1>
<P></P>
<A NAME="toc1"></A>
2017-09-23 23:54:48 +02:00
<H1>1. Good practices overview</H1>
2016-01-22 17:52:28 +01:00
<UL>
2017-09-23 23:54:48 +02:00
<LI>Do the basic checks showing imapsync works by itself where you run it.
2016-01-22 17:52:28 +01:00
<P></P>
<LI>Next, applying imapsync to your data,
continue with a <B>real user</B> account on the source imap server (host1)
and a <B>test</B> account on the destination imap server (host2).
<P></P>
It's the best advice I can give to learn imapsync, be confident in it, and
verify it will do what you expect it to do in your context, all of that
without much pain. So try imapsync with a real account at the source, aka host1,
and a test account at the destination, aka host2.
<P></P>
2018-05-07 16:04:23 +02:00
<LI>Next, once familiar and satisfied by the result on the host2 test account,
2016-01-22 17:52:28 +01:00
change to a real user account on host2 or just stop consider it a test one.
</UL>
<A NAME="toc2"></A>
<H1>2. Basic steps</H1>
<A NAME="toc3"></A>
<H2>2.1. Verifying imapsync works well on its own</H2>
<P>
Open a terminal and go to the imapsync directory.
The imapsync directory is the directory created by extraction
of the tarball (.tgz), its name is <CODE>imapsync-1.xxx</CODE> where <CODE>1.xxx</CODE>
2018-05-07 16:04:23 +02:00
is imapsync release number (1.882 at the time of this writing).
2016-01-22 17:52:28 +01:00
</P>
<PRE>
cd imapsync-1.xxx/
</PRE>
<P>
Verify imapsync runs on your system
</P>
<PRE>
./imapsync
</PRE>
<P>
2018-05-07 16:04:23 +02:00
It should output the help message.
2016-01-22 17:52:28 +01:00
</P>
<P>
If the previous command fails then there is an installation issue.
2017-09-23 23:54:48 +02:00
Go back to <A HREF="https://imapsync.lamiral.info/#install">https://imapsync.lamiral.info/#install</A> then
and read and apply the installation file corresponding to your
system and drop me an email about your issue.
2016-01-22 17:52:28 +01:00
</P>
<P>
2018-05-07 16:04:23 +02:00
Next, verify imapsync runs live tests. This check needs an Internet
2016-01-22 17:52:28 +01:00
access. It does a simple sync between two real dedicated
2017-09-23 23:54:48 +02:00
imap maiboxes located at the host test.lamiral.info
2016-01-22 17:52:28 +01:00
</P>
<PRE>
./imapsync --testslive
</PRE>
<P>
2018-05-07 16:04:23 +02:00
Now verify that the script examples/imapsync_example.sh runs fine:
2016-01-22 17:52:28 +01:00
</P>
<PRE>
sh examples/imapsync_example.sh
</PRE>
<P>
This script does the same thing than "<CODE>imapsync --testslive</CODE>" but it
2018-05-07 16:04:23 +02:00
uses explicitly the 6 parameters so it will be a good start
2016-01-22 17:52:28 +01:00
for your future own script.
</P>
<A NAME="toc4"></A>
<H2>2.2. Working with your data</H2>
<P>
2018-05-07 16:04:23 +02:00
I consider you're still in the imapsync top directory.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
Make a copy of the script <CODE>examples/imapsync_example.sh</CODE>
2016-01-22 17:52:28 +01:00
</P>
<PRE>
cp examples/imapsync_example.sh mysync
</PRE>
<P>
Check that the copy works as the original
</P>
<PRE>
sh mysync
</PRE>
<P>
So far so good, now we're going to work with your data.
</P>
<A NAME="toc5"></A>
<H2>2.3. Prepare your credentials</H2>
<P>
An IMAP account is accessed with 3 parameters,
</P>
<UL>
2017-09-23 23:54:48 +02:00
<LI>the imap server <B>host</B>. It's a server name or an ip address
<LI>the <B>user</B> name
<LI>the <B>password</B>
2016-01-22 17:52:28 +01:00
</UL>
<P>
2017-09-23 23:54:48 +02:00
Since imapsync job is to sync two imap accounts we need 3 + 3 = 6 parameters:
2016-01-22 17:52:28 +01:00
</P>
<UL>
2017-09-23 23:54:48 +02:00
<LI>Three parameters in order to read data from the source account: <B>host1</B>, <B>user1</B> and <B>password1</B>
<LI>Three parameters in order to copy this data to the destination account: <B>host2</B>, <B>user2</B> and <B>password2</B>
2016-01-22 17:52:28 +01:00
</UL>
<A NAME="toc6"></A>
<H2>2.4. Take a real user account as source</H2>
<P>
2018-05-07 16:04:23 +02:00
Even during the learning time with imapsync, you can take a
2017-09-23 23:54:48 +02:00
real user account as a source. There is also no problem if this account is
currently used by a user. By default, this account will only be read, no change will
be made by imapsync on it.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
Assuming that the imap source server name host1 is <B>origin.example.com</B>,
2016-01-22 17:52:28 +01:00
the user1 account name is <B>myuser1</B> and its password is <B>mysecret1</B>,
we now have the first three parameters.
</P>
<UL>
2017-09-23 23:54:48 +02:00
<LI>--host1 <B>origin.example.com</B>
2016-01-22 17:52:28 +01:00
<LI>--user1 <B>myuser1</B>
<LI>--password1 <B>mysecret1</B>
</UL>
<A NAME="toc7"></A>
<H2>2.5. Take a test user account as destination</H2>
<P>
Unlike the source side, the destination side will be modified by
imapsync. Therefore, for learning, checking and adjusting,
it is not a very good idea to use a real user imap account
the first times you play with imapsync.
</P>
<P>
If you really can't afford a test account on host2, it's ok,
2018-05-07 16:04:23 +02:00
imapsync is not that bad but you may have some work to do to fix some unwanted behavior.
Unwanted behavior is mostly folders names that you don't want to be the same on both sides.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
Assuming that the imap destination server name host2 is <B>destiny.example.com</B>,
2016-01-22 17:52:28 +01:00
the user2 account name is <B>myuser2</B> and its password is <B>mysecret2</B>,
we now have the next three parameters.
</P>
<UL>
2017-09-23 23:54:48 +02:00
<LI>--host2 <B>destiny.example.com</B>
2016-01-22 17:52:28 +01:00
<LI>--user2 <B>myuser2</B>
<LI>--password2 <B>mysecret2</B>
2016-09-19 17:15:41 +02:00
</UL>
<A NAME="toc8"></A>
<H2>2.6. Edit your own script mysync</H2>
<P>
2016-01-22 17:52:28 +01:00
Now edit the script <CODE>mysync</CODE> and replace the test values by yours.
2016-09-19 17:15:41 +02:00
</P>
<P>
2016-01-22 17:52:28 +01:00
You're ready for a dry test on your accounts.
2016-09-19 17:15:41 +02:00
</P>
2016-01-22 17:52:28 +01:00
<PRE>
sh mysync
</PRE>
2016-09-19 17:15:41 +02:00
<P>
2017-09-23 23:54:48 +02:00
Since the <CODE>mysync</CODE> script is a copy of <CODE>examples/imapsync_example.sh</CODE>,
2016-01-22 17:52:28 +01:00
your first run with your data should include three other options
2017-09-23 23:54:48 +02:00
<CODE>--automap</CODE> <CODE>--justfolders</CODE> <CODE>--dry</CODE>.
With <CODE>--dry</CODE> option, nothing will really be done on host2
2018-05-07 16:04:23 +02:00
but yet it will test whether the credentials are ok on both sides.
You'll encounter two successful logins, or one failure on host1,
or a successful login on host1 but a failure on host2.
If the login are ok, you will also observe if the folders mapping is ok.
2016-09-19 17:15:41 +02:00
</P>
<P>
2016-01-22 17:52:28 +01:00
If a login fails then double-check all three values that identify
the account, which are the host, the login name, and the password.
2016-09-19 17:15:41 +02:00
</P>
<P>
2016-01-22 17:52:28 +01:00
If the folders mapping proposed is not ok then you can fix it with
2018-05-07 16:04:23 +02:00
option <CODE>--f1f2</CODE>. The following example maps the source folder
2017-09-23 23:54:48 +02:00
"Sent Messages" to the destination folder "Sent". The double-quotes
are not part of the folders names but they should be used when special
characters like blanks are in the folders names:
2016-09-19 17:15:41 +02:00
</P>
2016-01-22 17:52:28 +01:00
<PRE>
2018-05-07 16:04:23 +02:00
./imapsync ... --f1f2 "Sent Messages=Sent"
2016-01-22 17:52:28 +01:00
</PRE>
<P>
As explained in the inline help or in the README:
</P>
<PRE>
--f1f2 str1=str2 : Force folder str1 to be synced to str2.
</PRE>
<P>
2018-05-07 16:04:23 +02:00
You're ready for a real test on your accounts, restricted to
2017-09-23 23:54:48 +02:00
folders. Remove <CODE>--dry</CODE> from the <CODE>mysync</CODE> script and rerun <CODE>mysync</CODE>:
2016-01-22 17:52:28 +01:00
</P>
<PRE>
sh mysync
</PRE>
2016-09-19 17:15:41 +02:00
<A NAME="toc9"></A>
2016-01-22 17:52:28 +01:00
<H1>3. Background knowledge about emailboxes</H1>
<P>
Three Internet protocols are used to access almost all email accounts:
POP3, IMAP, HTTP.
</P>
<P>
2017-09-23 23:54:48 +02:00
The oldest protocol still used to access mailboxes is POP3, the Post Office Protocol.
2018-05-07 16:04:23 +02:00
POP3 gives access to only one main box called INBOX.
</P>
<P>
With POP3, messages have no flags at all, no Seen/UnSeen, Forwarded, or Flagged labels.
</P>
<P>
It's not systematic but messages are often removed from a POP3 server
2017-09-23 23:54:48 +02:00
each time a software client looks into it,
so messages only appear on the client host that fetched them,
2018-05-07 16:04:23 +02:00
they are unavailable from any other system located elsewhere.
2016-01-22 17:52:28 +01:00
</P>
<P>
The second protocol to deal with email messages is IMAP, Internet Message Access Protocol.
2017-09-23 23:54:48 +02:00
IMAP gives access to a hierarchy of mailboxes also called folders. Other IMAP features are
2018-05-07 16:04:23 +02:00
concurrent accesses, tagging with flags, search by many criterium like date, subject, size etc.
</P>
<P>
2016-01-22 17:52:28 +01:00
The IMAP protocol presents most of the features POP lacks.
Messages stay on the imap server so any client on the network can access them
at any time from anywhere, the same messages with the same flags.
</P>
<P>
The third protocol to access email messages is HTTP, HyperText Transfer Protocol.
HTTP is the protocol to browse the web.
2018-05-07 16:04:23 +02:00
</P>
<P>
2017-09-23 23:54:48 +02:00
Web browsers like Google Chrome, Mozilla Firefox, Internet Explorer and Safari
2018-05-07 16:04:23 +02:00
are HTTP client software tools. You already know that so what's the point with HTTP mailboxes?
2017-09-23 23:54:48 +02:00
HTTP mailboxes are called webmails.
2018-05-07 16:04:23 +02:00
Webmails often offer the same features than imap servers
because webmails underlying storage systems are often imap servers.
</P>
<P>
Webmails systems like Gmail, Yahoo, Exchange, Zimbra or Office365 are also accessible via imap.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
The conclusion of this protocol review is that mailboxes can be
accessed using the IMAP protocol, most of the time.
Here comes imapsync.
2016-01-22 17:52:28 +01:00
</P>
2017-09-23 23:54:48 +02:00
<P>
In case the source mailbox is only accessible by the POP protocol,
2018-05-07 16:04:23 +02:00
you can use the tool <CODE>pop2imap</CODE> to sync them.
<CODE>pop2imap</CODE> is located at <A HREF="http://www.linux-france.org/prj/pop2imap/">http://www.linux-france.org/prj/pop2imap/</A>
2017-09-23 23:54:48 +02:00
</P>
<A NAME="toc10"></A>
<H1>4. Imapsync presentation</H1>
2016-01-22 17:52:28 +01:00
<P>
Software imapsync is a command line tool to
copy, migrate, backup or synchronize IMAP mailboxes.
</P>
<P>
Command line means imapsync is not graphical, it is textual.
Usually with command line tools you have to type characters
on your keyboard. But your fingers won't suffer much pain
2017-09-23 23:54:48 +02:00
typing on the keyboard because script examples are given,
2016-01-22 17:52:28 +01:00
nearly ready to run. Most of the time you only have to change
the main values in those files and adapt them to your context.
</P>
<P>
Don't be afraid, the mouse won't be forsaken.
You can still use the mouse to launch an editor,
select/copy/paste complete examples,
2018-05-07 16:04:23 +02:00
and run the little script with a double-click.
2016-01-22 17:52:28 +01:00
</P>
<P>
Imapsync runs on Linux, Windows and OS X (Macintosh world).
2018-05-07 16:04:23 +02:00
Imapsync is written in the Perl language and, thanks to the
Perl developers, Perl runs mostly everywhere. So does imapsync.
2016-01-22 17:52:28 +01:00
</P>
<P>
While operating systems have a lot in common, they sometimes differ,
2018-05-07 16:04:23 +02:00
especially within their syntax. I won't blame anyone, historically Windows
2016-01-22 17:52:28 +01:00
came after Unix. The marvelous designers in this old times
decided it would be very cool to not share exactly the same syntax
2018-05-07 16:04:23 +02:00
for doing the same things.
</P>
<P>
To designate an end of line, Unix uses the character \n
Windows uses two characters \r\n and Mac use \r.
Thanks guys, great great thinking!
Fifty years later, we still suffer from this...daily.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
To avoid you some headaches with systems no one masters
I will give examples in both worlds, Unix and Windows.
2016-01-22 17:52:28 +01:00
OS X users are in the Unix world nowadays so they must follow
the Unix examples.
</P>
2017-09-23 23:54:48 +02:00
<A NAME="toc11"></A>
<H1>5. Conventions</H1>
2016-01-22 17:52:28 +01:00
<P>
In order to simplify display or print,
each imapsync command line is usually written in several lines
but it could be written in one single line.
</P>
<P>
If you prefer to use the whole command written in one single line then
2017-09-23 23:54:48 +02:00
just remove the last visible character of each line ( \ or ^ ) and
2016-01-22 17:52:28 +01:00
also the carriage return character.
2017-09-23 23:54:48 +02:00
The last visible character means "command continues on next line";
it is the backslash \ character on Unix and the caret ^ character on Windows.
2016-01-22 17:52:28 +01:00
</P>
<P>
2017-09-23 23:54:48 +02:00
For example, on Unix, a command like the following
2016-01-22 17:52:28 +01:00
</P>
<PRE>
imapsync \
--host1 test.lamiral.info \
--user1 test1 \
--password1 secret1 \
...
</PRE>
<P>
is equivalent to
</P>
<PRE>
imapsync --host1 test.lamiral.info --user1 test1 --password1 secret1 ...
</PRE>
<P>
and on Windows
</P>
<PRE>
imapsync.exe ^
--host1 test.lamiral.info ^
--user1 test1 ^
--password1 secret1 ^
...
</PRE>
<P>
is equivalent to
</P>
<PRE>
imapsync --host1 test.lamiral.info --user1 test1 --password1 secret1 ...
</PRE>
2017-09-23 23:54:48 +02:00
<A NAME="toc12"></A>
<H1>6. Why start with a test account on destination host2?</H1>
2016-01-22 17:52:28 +01:00
<P>
A little explanation about this hint.
Imapsync is safe with accounts on host1,
it doesn't change anything on them, it just read them.
2017-09-23 23:54:48 +02:00
The exception of this safe principle is when <CODE>--delete1</CODE> option is used,
since <CODE>--delete1</CODE> removes on host1 each message successfully copied to host2,
messages that couldn't be transferred stay on host1.
2016-01-22 17:52:28 +01:00
</P>
<P>
It's not the same for destination accounts as imapsync writes on host2 accounts.
Imapsync creates folders on them, add messages, set flags on messages.
It isn't a safe behavior on a real account. So don't use a real user account
to test imapsync. Learn to use it and see what it does on a test account at host2.
</P>
<P>
2018-05-07 16:04:23 +02:00
What can badly happen? The most common bad behavior is
2016-01-22 17:52:28 +01:00
the folders mapping won't be what you expect because it is strictly
2018-05-07 16:04:23 +02:00
reproduced from host1 to host2. The second bad behavior is
2017-09-23 23:54:48 +02:00
duplicates on second run and after, it's rare but it can happen
when a imap server software changes headers "<CODE>Message-Id</CODE>" or "<CODE>Received</CODE>".
Solutions to avoid duplicates are often easy (There's a FAQ called <CODE>FAQ.Duplicates.txt</CODE> about that).
It's also possible to remove the duplicates on host2 but it's better to avoid them on user accounts at first,
users won't like that you mess up their mailboxes.
2016-01-22 17:52:28 +01:00
</P>
2017-09-23 23:54:48 +02:00
<A NAME="toc13"></A>
2018-05-07 16:04:23 +02:00
<H1>7. Imapsync default behavior</H1>
2016-01-22 17:52:28 +01:00
<P>
2018-05-07 16:04:23 +02:00
By default, unless explicitly told to do something else:
2016-01-22 17:52:28 +01:00
</P>
<UL>
2017-09-23 23:54:48 +02:00
<LI>Imapsync <B>goes ssl or tls</B> if possible
<LI>Imapsync syncs <B>all folders</B> of host1
<LI>Imapsync syncs <B>all messages</B> from host1, except duplicates.
<LI>Imapsync syncs <B>all flags</B>, at least all allowed by host2.
2016-01-22 17:52:28 +01:00
</UL>
2017-09-23 23:54:48 +02:00
<A NAME="toc14"></A>
<H1>8. To go further with imapsync</H1>
<P>
2016-01-22 17:52:28 +01:00
Imapsync has many options but you can ignore most of them
and still make great transfers.
2017-09-23 23:54:48 +02:00
</P>
2016-01-22 17:52:28 +01:00
<UL>
2017-09-23 23:54:48 +02:00
<LI>Option names all begin with two minus characters <CODE>--</CODE>, like <CODE>--automap</CODE> or <CODE>--dry</CODE> etc. (using one minus, like <CODE>-dry</CODE>, is ok)
<LI>Option names relative to the <B>source</B> account are ended with the number one <B><CODE>1</CODE></B>, like in <CODE>--host1</CODE>
<LI>Option names relative to the <B>destination</B> account are ended with the number two <B><CODE>2</CODE></B>, like in <CODE>--host2</CODE>
<LI>Some options need a <B>value</B> just after them, like <CODE>--host1</CODE> <B><CODE>source.example.com</CODE></B>, (the value is <CODE>source.example.com</CODE>)
<LI>Some options are standalone, like <B><CODE>--automap</CODE></B>
<LI>Any order is possible but when an option needs a value then the value must follow immediately its option name.
2016-01-22 17:52:28 +01:00
</UL>
<!-- html code generated by txt2tags 2.6 (http://txt2tags.org) -->
<!-- cmdline: txt2tags -i doc/TUTORIAL_Unix.t2t -t html -\-toc -o doc/TUTORIAL_Unix.html -->
</BODY></HTML>