Recently, I was required to download all my eMail from my IMAP-mail account. Doing this manually seemed like a lot of work, so needed to come up with a neat solution.
On GitHub I found Rob's python
" which comes along with a nice description on his blog voidnullness
. Rob's code was a good starting point for my task. However I did not only want to download my eMails but also extract header information and attachments from the downloaded files. So I needed to tweak his code a bit and came up with "maildump.py
Having downloaded all my eMails from my IMAP account using the python code above, I decided to convert my eMails into PDF documents. For this task I used the python "txt2pdf.py" program together with my short bash script:
echo $filename0 > $filename4
echo >> $filename4
cat $filename1 $filename2 $filename3 >> $filename4
python txt2pdf.py $filename4
This bash script is a quick and dirty solution. As such, it requires adaptation:
%04d are hard coded into the script and require manual modification.
NUMBEROFFILES represents the total number of eMails in the specified IMAP folder.
%04d is responsible for generating file names with leading zeros (this value corresponds to the line
DIGITCOUNT=4 in the python script). Finally,
FOLDER stands for the directory in which the downloaded eMails can be found.