|
Some time ago, my email provider, Fastmail.fm, went down for over 3 days. It was after this I decided to move over to Gmail. I had a need to move all of my old email (3 yrs worth) over to gmail. I found some solutions out there, but they seemed a little clunky. Here is how I solved it.
Luckily, Fastmail.fm provided an archiving feature that allowed you to download a .zip file of all the emails you specified. It came in the standard raw format, but each email was an individual file. I guess if you cat'd them all together it would be considered mbox, but I am not 100% sure.
Assuming you have a way to pipe in individual email messages, via mbox or by looping over some files, the following script sends the email to the email address you specify.
Some features of the script:
- It removes all BCC and CC headers;
- It forces the To header to be whatever you specify
- It does not modify the Date header
Required
- Perl
- Mail::Internet
- Mail::Sendmail
- File::Find (for the manyfiles.pl driver)
Usage
Assuming "file.eml" is an individual email message, you simply use the script in the following manner:
% bkp2gmail.pl --to="yournewemail@maildomain.tdl" --host=localhost \
--tag=appends_subject_with_this
Flag Descriptions:
- --to
email address to send email to; handles only one, and must not contain any brackets, > or <
- --host
smtp host; doesn't handle authentication and basically assumes localhost anyway
- --tag
appends the specified value to the subject line; this is extremely useful when importing into gmail since you can set up a filter to detect this string, label it, and archive it
Issues
- If your file names have spaces in them, you'll have to rename them; try with a command like:
find . | perl -ne'chomp; next unless -e;
$oldname = $_; s/ /_/g; next if -e; rename $oldname, $_'
- The script doesn't handle mbox, so you'll need some way to extract out each message;
- It basically assumes you are using localhost to send your mail - it is not set up to handle hosts that require authentication
- Gmail retains the sent date, but displays it via received date; there is no way that I know of to get around this, but it is easy enough to set up a lable and take to the time to manually tag the new messages - unless you have a ton of them. If you have a better solution, let me know.
Credits
This is script is mostly an adaptation to smtp.pl, which is very useful when coupled with mutt.
Your name goes here if you provide a bug fix or feature patch:)
Special Instructions for Fastmail.fm users
- Archive your messages (should give you a .zip file to download)
- On a computer where you have set this script up, unzip the archive - preferably in a new directory; this should give you a ".eml" file for each email in the achive
- Be sure to rename the files so they don't have spaces in them; see how to do this above in the "Issues" section.
- Run the script "eml2gmail.sh"; it will loop over all *.eml files in the present working directory and will cat it into the script. Once a .eml file is processed, the file name is appened with ".done".
I am assuming that you are already set up. You probably only want to use this if you are on some sort of *nix platform and can send emails from it via commandline. This is straighforward, but pretty hardcore for the uninitiated *nix user. I recommend not trying to use this on Windows.
Download
THIS PROGRAM IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- bkp2gmail.pl
The main Perl script
- eml2gmail.sh
A driver for bkp2gmail.pl
- manyfiles.pl
A Perl driver that is useful when you have a very large amount of files, and eml2gmail.sh just won't cut it
I don't provide support, but will answer questions if they are explicitly about this script. I won't help with linux or smtp questions. My NEW email is estabd at gmail dot com.
Closing Remarks
I used this to solve a need I had. I am more than happy to accept bug or feature patches. I hope you find this as useful as I did.
Links
|
|