aboutsummaryrefslogtreecommitdiffstats
path: root/archivemail.1
blob: 5dd063f54af8aae2edef9602828a737e6cf5805f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
.\" This manpage has been automatically generated by docbook2man 
.\" from a DocBook document.  This tool can be found at:
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/> 
.\" Please send any bug reports, improvements, comments, patches, 
.\" etc. to Steve Cheng <steve@ggi-project.org>.
.TH "ARCHIVEMAIL" "1" "30 July 2010" "SP" ""

.SH NAME
archivemail \- archive and compress your old email
.SH SYNOPSIS

\fBarchivemail\fR [ \fBoptions\fR ] \fB\fIMAILBOX\fB\fR\fI ...\fR

.SH "DESCRIPTION"
.PP
archivemail is a tool for archiving and compressing old email in mailboxes.
By default it will read the mailbox \fIMAILBOX\fR, moving messages
that are older that the specified number of days (180 by default) to a
\fBmbox\fR(5)-format mailbox in the same directory that is compressed
with \fBgzip\fR(1)\&.
It can also just delete old email rather than archive it.
.PP
\fBarchivemail\fR supports reading  \fBIMAP\fR,
\fBMaildir\fR, \fBMH\fR and \fBmbox\fR-format
mailboxes, but always writes \fBmbox\fR-format archives.
.PP
Messages that are flagged important are not archived or deleted unless
explicitely requested with the \fB--include-flagged\fR option.
Also, \fBarchivemail\fR can be configured not to archive unread mail, or
to only archive messages larger than a specified size. 
.PP
To archive an \fBIMAP\fR-format mailbox, use the format
\fIimap://username:password@server/mailbox\fR to specify the mailbox. 
You can omit the password from the URL; use the
\fB--pwfile\fR option to make \fBarchivemail\fR read the 
password from a file, or alternatively just enter it upon request. 
If the \fB--pwfile\fR option is set, \fBarchivemail\fR does not
look for a password in the URL, and the colon is not considered a 
delimiter.
Substitute '\fBimap\fR\&' with '\fBimaps\fR\&', and 
\fBarchivemail\fR will establish a secure SSL connection.  
See below for more \fBIMAP\fR peculiarities. 
.SH "OPTIONS"
.TP
\fB    -d \fINUM\fB, --days=\fINUM\fB\fR
Archive messages older than \fINUM\fR days.  
The default is 180. This option is incompatible with the
\fB--date\fR option below.
.TP
\fB    -D \fIDATE\fB, --date=\fIDATE\fB\fR
Archive messages older than \fIDATE\fR\&.
\fIDATE\fR can be a date string in ISO format (eg '2002-04-23'), 
Internet format (eg '23 Apr 2002') or Internet format with full month names 
(eg '23 April 2002'). Two-digit years are not supported.
This option is incompatible with the \fB--days\fR option above.
.TP
\fB    -o \fIPATH\fB, --output-dir=\fIPATH\fB\fR
Use the directory name \fIPATH\fR to store the
mailbox archives. The default is the same directory as the mailbox to be
read.
.TP
\fB    -P \fIFILE\fB, --pwfile=\fIFILE\fB\fR
Read IMAP password from file \fIFILE\fR
instead of from the command line.  Note that this will probably not work if you
are archiving folders from more than one IMAP account. 
.TP
\fB    -F \fISTRING\fB, --filter-append=\fISTRING\fB\fR
Append \fISTRING\fR to the IMAP filter string. 
For IMAP wizards. 
.TP
\fB    -s \fINAME\fB, --suffix=\fINAME\fB\fR
Use the suffix \fINAME\fR to create the filename used for archives.  
The default is \fI_archive\fR\&. For example, if you
run \fBarchivemail\fR on a mailbox called
\fIexsouthrock\fR, the archive will be created
with the filename \fIexsouthrock_archive.gz\fR\&.

\fINAME\fR is run through the \fBpython\fR(1) \fBtime.strftime()\fR
function, which means that you can specify any of the following special
directives in \fINAME\fR to make archives named after the archive
cut-off date:
.RS
.TP 0.2i
\(bu
\fB%a\fR 
Locale's abbreviated weekday name.
.TP 0.2i
\(bu
\fB%A\fR 
Locale's full weekday name.
.TP 0.2i
\(bu
\fB%b\fR 
Locale's abbreviated month name.
.TP 0.2i
\(bu
\fB%B\fR 
Locale's full month name.
.TP 0.2i
\(bu
\fB%c\fR 
Locale's appropriate date and time representation.
.TP 0.2i
\(bu
\fB%d\fR 
Day of the month as a decimal number [01,31].
.TP 0.2i
\(bu
\fB%H\fR 
Hour (24-hour clock) as a decimal number [00,23].
.TP 0.2i
\(bu
\fB%I\fR 
Hour (12-hour clock) as a decimal number [01,12].
.TP 0.2i
\(bu
\fB%j\fR 
Day of the year as a decimal number [001,366].
.TP 0.2i
\(bu
\fB%m\fR 
Month as a decimal number [01,12].
.TP 0.2i
\(bu
\fB%M\fR 
Minute as a decimal number [00,59].
.TP 0.2i
\(bu
\fB%p\fR 
Locale's equivalent of either AM or PM.
.TP 0.2i
\(bu
\fB%S\fR 
Second as a decimal number [00,61]. (1)
.TP 0.2i
\(bu
\fB%U\fR 
Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
.TP 0.2i
\(bu
\fB%w\fR 
Weekday as a decimal number [0(Sunday),6].
.TP 0.2i
\(bu
\fB%W\fR 
Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
.TP 0.2i
\(bu
\fB%x\fR 
Locale's appropriate date representation.
.TP 0.2i
\(bu
\fB%X\fR 
Locale's appropriate time representation.
.TP 0.2i
\(bu
\fB%y\fR 
Year without century as a decimal number [00,99].
.TP 0.2i
\(bu
\fB%Y\fR 
Year with century as a decimal number.
.TP 0.2i
\(bu
\fB%Z\fR 
Time zone name (or by no characters if no time zone exists).
.TP 0.2i
\(bu
\fB%%\fR 
A literal "%" character.
.RE
.TP
\fB    -S \fINUM\fB, --size=\fINUM\fB\fR
Only archive messages that are \fINUM\fR bytes or
greater.
.TP
\fB    -n, --dry-run\fR
Don't write to any files -- just show what would have been done. This is
useful for testing to see how many messages would have been archived.
.TP
\fB    -u, --preserve-unread\fR
Do not archive any messages that have not yet been read. \fBarchivemail\fR
determines if a message in a \fBmbox\fR-format or
\fBMH\fR-format mailbox has been read by looking at the
\fBStatus\fR header (if it exists). If the status
header is equal to 'RO' or 'OR' then \fBarchivemail\fR assumes the
message has been read. \fBarchivemail\fR determines if a
\fBmaildir\fR message has
been read by looking at the filename. If the filename contains an 'S' after 
\fI:2,\fR then it assumes the message has been read.
.TP
\fB    --dont-mangle\fR
Do not mangle lines in message bodies beginning with "From ".  When archiving
a message from a mailbox not in \fBmbox\fR format, by default
\fBarchivemail\fR mangles such lines by prepending a '>' to them, since mail
user agents might otherwise interpret these lines as message separators.
Messages from \fBmbox\fR folders are never mangled.  See \fBmbox\fR(5) for more
information.
.TP
\fB    --delete\fR
Delete rather than archive old mail. Use this option with caution!
.TP
\fB    --copy\fR
Copy rather than archive old mail. 
Creates an archive, but the archived messages are not deleted from the
originating mailbox, which is left unchanged.
This is a complement to the \fB--delete\fR option, and mainly useful for
testing purposes. 
Note that multiple passes will create duplicates, since messages are blindly
appended to an existing archive.
.TP
\fB    --all\fR
Archive all messages, without distinction.
.TP
\fB    --include-flagged\fR
Normally messages that are flagged important are not archived or deleted. If
you specify this option, these messages can be archived or deleted just like
any other message.
.TP
\fB    --no-compress\fR
Do not compress any archives.
.TP
\fB    --warn-duplicate\fR
Warn about duplicate \fBMessage-ID\fRs that appear in the input
mailbox.
.TP
\fB    -v, --verbose\fR
Reports lots of extra debugging information about what is going on.
.TP
\fB    --debug-imap=\fINUM\fB\fR
Set IMAP debugging level. This makes \fBarchivemail\fR dump its
conversation with the IMAP server and some internal IMAP
processing to stdout\&.  Higher values for \fINUM\fR give more
elaborate output.  Set \fINUM\fR to 4 to see all exchanged 
IMAP commands.  (Actually, \fINUM\fR is just passed 
literally to imaplib.Debug\&.)
.TP
\fB    -q, --quiet\fR
Turns on quiet mode. Do not print any statistics about how many messages were
archived. This should be used if you are running \fBarchivemail\fR from
cron.
.TP
\fB    -V, --version\fR
Display the version of \fBarchivemail\fR and exit.
.TP
\fB    -h, --help\fR
Display brief summary information about how to run \fBarchivemail\fR\&.
.SH "NOTES"
.PP
\fBarchivemail\fR requires \fBpython\fR(1) version 2.3 or later.
When reading an \fBmbox\fR-format mailbox, \fBarchivemail\fR will
create a lockfile with the extension \fI\&.lock\fR so that
procmail will not deliver to the mailbox while it is being processed. It will
also create an advisory lock on the mailbox using \fBlockf\fR(2)\&.
The archive is locked in the same way when it is updated.
\fBarchivemail\fR will also complain and abort if a 3rd-party modifies the
mailbox while it is being read.
.PP
\fBarchivemail\fR will always attempt to preserve the mode,
last-access and last-modify times of the input mailbox. However, archive
mailboxes are always created with a mode of \fB0600\fR\&.
If \fBarchivemail\fR finds a pre-existing archive mailbox it
will append rather than overwrite that archive.
\fBarchivemail\fR will refuse to operate on mailboxes that are symbolic 
links or create tempfiles or archives in world-writable directories.
.PP
\fBarchivemail\fR attempts to find the delivery date of a message by
looking for valid dates in the following headers, in order of precedence: 
\fBDelivery-date\fR,
\fBReceived\fR, 
\fBResent-Date\fR and
\fBDate\fR\&.
If it cannot find any valid date in these headers, it
will use the last-modified file timestamp on \fBMH\fR and
\fBMaildir\fR format mailboxes, or the date on the 
\fBFrom\fR line on \fBmbox\fR-format mailboxes.
.PP
A conversion from other formats to \fBmbox\fR(5) will silently overwrite existing
\fBStatus\fR and \fBX-Status\fR message headers. 
.SS "IMAP"
.PP
When \fBarchivemail\fR processes an \fBIMAP\fR folder, all messages 
in that folder will have their \\Recent flag unset, and they will 
probably not show up as 'new' in your user agent later on. 
There is no way around this, it's just how \fBIMAP\fR works. 
This does not apply, however, if you run \fBarchivemail\fR with the options
\fB--dry-run\fR or \fB--copy\fR\&.
.PP
\fBarchivemail\fR relies on server-side searches to determine the messages
that should be archived. 
When matching message dates, \fBIMAP\fR servers refer to server internal
message dates, and these may differ from both delivery time of a message and 
its \fBDate\fR header. 
Also, there exist broken servers which do not implement server side searches. 
.SS "IMAP URLS"
.PP
\fBarchivemail\fR\&'s \fBIMAP\fR URL parser was written
with the RFC 2882 (\fIInternet Message
Format\fR) rules for the local-part of email addresses
in mind.
So, rather than enforcing an URL-style encoding of non-ascii
and reserved characters, it allows to double-quote the username and password.
If your username or password contains the delimiter characters '@' or ':', just
quote it like this:
\fIimap://"username@bogus.com":"password"@imap.bogus.com/mailbox\fR\&.
You can use a backslash to escape double-quotes that are part of a quoted
username or password.
Note that quoting only a substring will not work, and be aware that your shell
will probably remove unprotected quotes or backslashes. 
.PP
\fBarchivemail\fR tries to be smart when handling mailbox paths. 
In particular, it will automatically add an IMAP NAMESPACE 
prefix to the mailbox path if necessary; and if you are archiving a subfolder,
you can use the slash as a path separator instead of the IMAP server's
internal representation.
.SH "EXAMPLES"
.PP
.PP
To archive all messages in the mailbox \fIdebian-user\fR that
are older than 180 days to a compressed mailbox called
\fIdebian-user_archive.gz\fR in the current directory: 

.nf
bash$ \fBarchivemail debian-user\fR
.fi
.PP
.PP
To archive all messages in the mailbox \fIdebian-user\fR that
are older than 180 days to a compressed mailbox called
\fIdebian-user_October_2001.gz\fR (where the current month and
year is April, 2002) in the current directory: 

.nf
bash$ \fBarchivemail --suffix '_%B_%Y' debian-user\fR
.fi
.PP
.PP
To archive all messages in the mailbox \fIcm-melb\fR that
are older than the first of January 2002 to a compressed mailbox called
\fIcm-melb_archive.gz\fR in the current directory: 

.nf
bash$ \fBarchivemail --date'1 Jan 2002' cm-melb\fR
.fi
.PP
.PP
Exactly the same as the above example, using an ISO date format instead:

.nf
bash$ \fBarchivemail --date=2002-01-01 cm-melb\fR
.fi
.PP
.PP
To delete all messages in the mailbox \fIspam\fR that
are older than 30 days:

.nf
bash$ \fBarchivemail --delete --days=30 spam\fR
.fi
.PP
.PP
To archive all read messages in the mailbox \fIincoming\fR that
are older than 180 days to a compressed mailbox called
\fIincoming_archive.gz\fR in the current directory: 

.nf
bash$ \fBarchivemail --preserve-unread incoming\fR
.fi
.PP
.PP
To archive all messages in the mailbox \fIreceived\fR that
are older than 180 days to an uncompressed mailbox called 
\fIreceived_archive\fR in the current directory:

.nf
bash$ \fBarchivemail --no-compress received\fR
.fi
.PP
.PP
To archive all mailboxes in the directory \fI$HOME/Mail\fR 
that are older than 90 days to compressed mailboxes in the
\fI$HOME/Mail/Archive\fR directory:

.nf
bash$ \fBarchivemail -d90 -o $HOME/Mail/Archive $HOME/Mail/*\fR
.fi
.PP
.PP
To archive all mails older than 180 days from the given \fBIMAP\fR
INBOX to a compressed mailbox INBOX_archive.gz in the
\fI$HOME/Mail/Archive\fR directory, quoting the password and
reading it from the environment variable \fBPASSWORD\fR:

.nf
bash$ \fBarchivemail -o $HOME/Mail/Archive imaps://user:'"'$PASSWORD'"'@example.org/INBOX\fR 
.fi
.PP
Note the protected quotes. 
.SH "TIPS"
.PP
Probably the best way to run \fBarchivemail\fR is from your \fBcrontab\fR(5)
file, using the \fB--quiet\fR option.
Don't forget to try the \fB--dry-run\fR and perhaps the
\fB--copy\fR option for non-destructive testing.
.SH "EXIT STATUS"
.PP
Normally the exit status is 0. Nonzero indicates an unexpected error.
.SH "BUGS"
.PP
If an \fBIMAP\fR mailbox path contains slashes, the archive filename
will be derived from the basename of the mailbox. 
If the server's folder separator differs from the Unix slash and is used in the
\fBIMAP\fR URL, however, the whole path will be considered
the basename of the mailbox. 
E.g. the two URLs
\fBimap://user@example.com/folder/subfolder\fR and
\fBimap://user@example.com/folder.subfolder\fR will be
archived in \fIsubfolder_archive.gz\fR and
\fIfolder.subfolder_archive.gz\fR, respectively, although they
might refer to the same \fBIMAP\fR mailbox. 
.PP
\fBarchivemail\fR does not support reading \fBMMDF\fR or
\fBBabyl\fR-format mailboxes. In fact, it will probably think it is 
reading an \fBmbox\fR-format mailbox and cause all sorts of problems.
.PP
\fBarchivemail\fR is still too slow, but if you are running from \fBcrontab\fR(5)
you won't care. Archiving \fBmaildir\fR-format mailboxes should be
a lot quicker than \fBmbox\fR-format mailboxes since it is less
painful for the original mailbox to be reconstructed after selective message 
removal.
.SH "SEE ALSO"

\fBpython\fR(1), \fBgzip\fR(1), \fBmutt\fR(1), \fBprocmail\fR(1)
.SH "URL"
.PP
The \fBarchivemail\fR home page is currently hosted at 
sourceforge <URL:http://archivemail.sourceforge.net>
.SH "AUTHOR"
.PP
This manual page was written by Paul Rodger <paul at paulrodger dot
com>\&. Updated and supplemented by Nikolaus Schulz
<microschulz@web.de>