Upload .eml files to Gmail over IMAP

1

2

I have a bunch of directories of eml files that I want upload to gmail using IMAP. I've used IMAPSync in the past to sync two IMAP accounts but these messages are just sitting on a file system as eml files they are not in an existing IMAP account where I can sync them. The eml files are all named via message ID. I want to maintain all the message properties and message attachments so that when they are in gmail I can search them and view them as complete messages. The file structure is as such.

2015mailarchives
├── 010115.xyz.archive
│   ├── account.manager
│   │   └── in
│   │       ├── 65199001.eml
│   │       ├── 65754836.eml
│   │       ├── 65860605.eml
│   │       ├── 65867970.eml
│   │       ├── 65990249.eml
│   │       ├── 65998348.eml
│   │       ├── 66004688.eml
│   │       ├── 66022610.eml
│   │       ├── 66107473.eml
│   │       ├── 66254739.eml
│   │       ├── 66293987.eml
│   │       ├── 66304813.eml
│   │       └── 66317500.eml
│   ├── adam.beck
│   │   ├── in
│   │   │   ├── 64633604.msg.eml
│   │   │   ├── 64634191.msg.eml
│   │   │   ├── 64635386.msg.eml
│   │   │   ├── 64635388.msg.eml

I don't really have to maintain the file structure. All I am trying to accomplish is to create a backup of the messages that can be searched quickly on gmail.

Any ideas on how to accomplish such a task? The files are on a headless linux box so I was hoping for something in bash, perl, python, etc.

mpmackenna

Posted 2016-10-28T16:42:57.783

Reputation: 35

1Are those regular plain-text .eml's or MS Outlook binary .eml's? – user1686 – 2016-10-28T16:54:11.000

Plain text. I can read them in vi. – mpmackenna – 2016-10-28T17:49:43.473

Answers

1

Many "mailbox sync" tools also support the Maildir and/or MH storage formats alongside IMAP. Conveniently, both of them consist of simple directories with one file per message:

  • To turn a directory into a Maildir folder (supported by nearly all programs), first create subdirectories cur, new, tmp, then move all message files under new/.

  • Alternatively, in case the program needs MH format, rename all messages by number (1, 2, 3… – no extension or anything) and create a blank .mh_sequences file.

Now that the directory is a valid Maildir folder, you can use OfflineIMAP or imapsync to transfer its contents somewhere else. Or run mutt -f account.manager/ to open the directory as a mail folder in Mutt; use Shift+T . Enter to select all messages, and Shift+C imaps://foo@imap.gmail.com Enter to copy them to the IMAP server.

Note: This assumes standard RFC 822 formatted messages in those .eml files – it won't work with Outlook's binary .eml format.

Also, beware of Google Apps' bandwidth limits – you can upload up to 500 MB per month.

user1686

Posted 2016-10-28T16:42:57.783

Reputation: 283 655