Categorygithub.com/mlnoga/go-imap-backup
modulepackage
0.0.0-20240522133400-c1ae5e09f2f2
Repository: https://github.com/mlnoga/go-imap-backup.git
Documentation: pkg.go.dev

# README

go-imap-backup

Backup, restore and delete old messages from an IMAP server.

Usage

go build, then go-imap-backup [-flags] command, where command is one of:

  • query fetch folder and message overview from IMAP server
  • lquery fetch folder and message metadata from local storage
  • backup save new messages on IMAP server to local storage
  • restore restore messages from local storage to IMAP server
  • delete delete older messages from IMAP server

Flags must be given before the command. The available flags are:

FlagDescriptionDefault
-sIMAP server name(read from console)
-pIMAP port number993
-uIMAP user name(read from console)
-PIMAP password(read from console)
-lLocal storage path(server)/(user)
-mAge limit for deletion in months, must be positive24
-fForce deletion of older messages without confirmation promptfalse
-rRestrict command to a comma-separated list of folders(blank)
-RNumber of retries for failed operations3
-dDelay in seconds between retries10

Local storage

Backups are stored locally in a directory tree server/user/, which is created by the backup command if necessary. For each folder on the IMAP server, the local directory contains both a mailbox file named folder.mbox, and an index of the messages therein called folder.idx.

The .mbox files follow mboxo format as defined here. That is, they do not quote lines starting with From . This preserves message sizes, checksums and signature validities. The backup tool avoids ambiguities arising from this by always addressing the .mbox file according to the indices and offsets in the corresponding .idx file.

The .idx file is a text file with one newline-separated line per message. Each line consists of the following tab-separated columns:

ColumnDescription
UidValidityA unique 32-bit integer identifier for an Imap folder
UidA unique 32-bit integer identifier for a message inside an Imap folder
SizeThe size of the email message in bytes
OffsetThe starting offset of the email message in the .mbox file

Note that the offset points directly at the start of the message itself, not at the separator line From [email protected] timestamp preceding it in the .mbox file. The size is the exact size of the message as well, excluding the blank separator line following the message in the .mbox file.

License

GPL v3

Libraries used

This project uses a number of open source libraries. Please refer to their respective repositories for licensing terms.

# Functions

Delete messages before the given time from an Imap server.
No description provided by the author
Parses given bytes as an email message, and returns the timestamp at the end of the first "Received" header as a go time.Time value.
Retrieves a list of all folders from an Imap server.
Creates local metadata for an imap folder by fetching metadata for all its messages.
Open a local mail folder for appending messages.
Open local mail folder message and index file for reading.

# Structs

Metadata for a folder and its messages on an IMAP server or in a local file.
A local mail folder, consisting of an .mbox file and its corresponding index .idx.
Metadata for an email message on an IMAP server or in a local file.