# loaddefs link d_QNial_mine 'email - save Thunderbird email folder as html files.ndf' # www.BillHowell.ca 03May2020 initial built on top of 'email - split Thunderbird email folder.ndf' # saves each email in a Thunderbird email folder as an html file # 1st use : "Cool emails" on my website # 04May2020 Problems : - [To, CC]: email lists only include trext on first line of multi-line lists. - email addresses in htmlHdr are invisible. This is dangerous because they can still be pulled from the email, and privacy is broken. - images could be saved in the output dir and shown in the p_emlHtml - apart from [txt, html] other codings aren't formatted properly - problems with strings.ndf - Howell_find etc f_emailSave := 'email - save Thunderbird email folder as html files.ndf' ; loaddefs_start f_emailSave ; #************ # List of operators, generated with : # $ cat "$d_Qndfs""email - save Thunderbird email folder as html files.ndf" | grep "^#]" | sed 's/^#\]/ /' # #*********** # Setup (kind of like header info) loaddefs link d_QNial_mine 'email - split Thunderbird email folder.ndf' ; # only the operator preprocess_folder is used from 'email - split Thunderbird email folder.ndf' flag_break := l ; flag_debug := o ; # Reminder of debug setup... # IF flag_break = l THEN Break ; ENDIF ; #IF flag_break = l THEN Break ; ENDIF ; # loaddefs link d_QNial_mine 'email - save Thunderbird email folder as html files.ndf' #*********************************************** #] emlAddress_format IS OP toFromCCLines - emlAddress_format IS OP toFromCCLines { LOCAL eml emlList emlPlusL line ; emlList := strings_between '<' '>' toFromCCLines ; emlPlusL := ('A HREF="mailto:' EACHRIGHT link emlList) EACHLEFT link '"><' ; emlPlusL := emlPlusL EACHBOTH link emlList ; emlPlusL := emlPlusL EACHLEFT link '>' toFromCCLines # emlAddress_format toFromCCLines #*********************************************** #] write_htmlHdr IS OP fout emlSubject emlFrom emlDate emlTo emlCC - # 03May2020 NOT FINISHED! - too much work, with not much chance of getting formatting right with a reasonable amount of effort! - better to simply save each email, and auto-remove [email addresses, names] but even that may be faster manually? - except filenames I have to generate as well! - arrgghhh! write_htmlHdr IS OP fout emlSubject emlFrom emlDate emlTo emlCC { fout EACHRIGHT writefile '' '' ; writefile fout (link '' emlSubject '') ; fout EACHRIGHT writefile '' '' '' '
' ; writefile fout (link 'Subject: ' (9 drop emlSubject) '
' ) ; writefile fout (link 'From: ' (emlAddress_format (6 drop emlFrom )) '
' ) ; writefile fout (link 'Date: ' (6 drop emlDate ) '
' ) ; writefile fout (link 'To: ' (emlAddress_format (4 drop emlTo )) '
' ) ; writefile fout (link 'Cc: ' (emlAddress_format (4 drop emlCC )) '

' ) ; fout EACHRIGHT writefile '' '' '' '' '' ; } #*********************************************** #] write_htmlEnd IS OP fout - # 03May2020 NOT FINISHED! write_htmlEnd IS OP fout { fout EACHRIGHT writefile '' '' ; } #*********************************************** #] emailFolder_saveAs_htmls IS OP p_log d_fldrSrc f_Src d_htmlOut - split email folder into html files # 03May2020 created from emailRead_one - special case for html file outputs # this is an anomalous operator - doesn't really fit in the the whole "splitFolder" idea # but it easily uses the other operators in this file, and I avoid code redundancy [errors, updating] # 03May2020 - with a_Howell cool emails' it is obvious that the lastline thing doesn't work # This kills me, as 'From - ' could easily arise in normal email text # they should have coded, eg : '#] From - ' or something! (shitty job) write 'loading emailFolder_saveAs_htmls' ; # loaddefs link d_QNial_mine 'email - split Thunderbird email folder.ndf' emailFolder_saveAs_htmls IS OP p_log d_fldrSrc f_Src d_htmlOut { LOCAL finn flog fout line p_emlHtml p_fldrSrc p_fldrTwix p_fldrTmp flag_header flag_subject flag_from flag_date flag_to flag_cc emlSubject emlFrom emlDate emlTo emlCC ; NONLOCAL email_filter_phrase mime_expand_flag massEmailRemove_flag p_emlOne p_emlOner p_last_FROM_processed ; % ; p_fldrSrc := link d_fldrSrc f_Src ; p_fldrTwix := link d_temp f_Src ' Twix.txt' ; p_fldrTmp := link d_temp f_Src ' temp.txt' ; flog := 1 ; % 03May2020 output to screen for now ; % flog := % ; mime_expand_flag := l ; % expand mime, the "key strings" (keyStrs) may be in the mime ; massEmailRemove_flag := o ; % ONLY if mime has been expanded (otherwise will often miss!) ; % ; writefile flog '' ; writefile flog '*************************************' ; writefile flog (link 'emailFolder_saveAs_htmls start : ' timestamp_DDMMMYYYY_HMS '') ; writefile flog '' ; % ; % count the emails ; write link 'email count= ' (string email_count p_fldrSrc) ; % depending on options, remove [massEmail, images], mime-to-text, ; preprocess_folder p_fldrSrc p_fldrTwix p_fldrTmp ; % ; flag_txt := o ; flag_header flag_subject flag_from flag_date flag_to flag_cc := 6 reshape l ; emlSubject emlFrom emlDate emlTo emlCC := 5 reshape '' ; finn := open p_fldrTmp "r ; % ; WHILE (~= ??eof (line := readfile finn)) DO % first read the email header and extract [emlSubject emlFrom emlDate emlTo emlCC] ; IF flag_header THEN IF flag_subject THEN IF (= (9 take line) 'Subject: ') THEN emlSubject := line ; flag_subject := o ; ENDIF ; ENDIF ; IF flag_from THEN IF (= (6 take line) 'From: ' ) THEN emlFrom := line ; flag_from := o ; ENDIF ; ENDIF ; IF flag_date THEN IF (= (6 take line) 'Date: ' ) THEN emlDate := line ; flag_date := o ; ENDIF ; ENDIF ; IF flag_to THEN IF (= (4 take line) 'To: ' ) THEN emlTo := line ; flag_to := o ; ENDIF ; ENDIF ; IF flag_cc THEN IF (= (4 take line) 'Cc: ' ) THEN emlCC := line ; flag_cc := o ; ENDIF ; ENDIF ; IF (= 'Content-Type: text/plain' (24 take line)) THEN flag_txt := l ; ENDIF ; IF (= 'Content-Transfer-Encoding' (25 take line)) THEN flag_header := o ; dater := emlDate_to_YYMMDD emlDate ; write link d_htmlOut dater ' ' emlSubject '.html' ; p_emlHtml := link d_htmlOut dater ' ' emlSubject '.html' ; fout := open p_emlHtml "w ; write_htmlHdr fout emlSubject emlFrom emlDate emlTo emlCC ; ENDIF ; % next read the rest of the email header and extract [emlSubject, emlFrom, emlDate, emlTo, emlCC] ; ELSE IF (= 'From - ' (7 take line)) THEN write_htmlEnd fout ; close fout ; flag_txt := o ; flag_header flag_subject flag_from flag_date flag_to flag_cc := 6 reshape l ; emlSubject emlFrom emlDate emlTo emlCC := 5 reshape '' ; ELSE IF flag_txt THEN writefile fout (link line '
') ; ELSE writefile fout line ; ENDIF ; ENDIF ; ENDIF ; ENDWHILE ; % ; EACH close finn flog ; % log summary info ; host link 'ls >>"' flog '" -lh "' d_temp '" ' ; writefile flog '' ; writefile flog (link 'emailFolder_saveAs_htmls end : ' timestamp_DDMMMYYYY_HMS '') ; writefile flog '' ; } #******************************** # Old specify [input, output] files : # 03May2020 for "Cool emails" on my website p_log := link d_Qndfs 'email - save Thunderbird email folder as html files log.txt' ; d_fldrSrc := '/home/bill/Thunderbird/n4caryuo.default/Mail/Local Folders/' ; f_Src := 'a_Howell cool emails' ; d_htmlOut := d_temp ; #********************************* # Procedure : # 1. compact Thunderbird email folderList. There is no need to copy the targeted email folder, as emailFolder_saveAs_htmls doesn't modify it. # 2. specify [input, output] files : (when putting in new specs - save those below to section above, "Old specify [input, output] files") : p_log := link d_Qndfs 'emailFolder_saveAs_htmls log.txt' ; d_fldrSrc := '/home/bill/Thunderbird/n4caryuo.default/Mail/Local Folders/' ; f_Src := 'a_Howell cool emails' ; d_htmlOut := d_temp ; # 3. qnial> loaddefs link d_QNial_mine 'email - save Thunderbird email folder as html files.ndf' # 4. qnial> emailFolder_saveAs_htmls p_log d_fldrSrc f_Src d_htmlOut loaddefs_ended f_emailSave ; # enddoc