''' 2021-05-22 To Dead Code previously entitled: iphone_email_notes_ideas_old Created on Nov 13, 2018 @author: Brett Paufler Copyright Brett Paufler For use with emailed copies of iPhone IDEAS notes Assumes a single Ideas eml file Extracts text from email (first in list, only) Backs out =20 (and other) escape sequences Removes headers and footers Splits by newline Exports to a text file

whatever text here

HEADER_VALUE = h2, but can be changed EXPORT_BACKWARDS = True, if False order is as written This was overwhelmingly copy/paste from another iPhone notes file and took maybe a half hour ''' #Reverse the List, making the oldest entry firse EXPORT_BACKWARDS = True HEADER_VALUE = 'h2' import email from os import listdir from os.path import join as path_join #Hardwired directories in and out dir_in = '.\\input\\' dir_out = '.\\output\\' #list of all the '.eml' files in input directory emails_list = [path_join(dir_in, f) for f in listdir(dir_in) if f.endswith('.eml')] #We are assuming there is only one of interest #So, first item on list is item of interest ideas_email = emails_list[0] print ideas_email #Extracts full text from email #Assumes text only, no images, etc msg = email.message_from_file(open(ideas_email)) attachments = msg.get_payload()#[01] full_text = str(attachments[0]) full_text = full_text.strip() print full_text #Reverse Markup Encodings Using Equals Sign unescaped_text = full_text.replace('=20', '') unescaped_text = unescaped_text.replace('=\n', '') print unescaped_text #Splits Text into return separated ('\n') items line_items = unescaped_text.split('\n') print line_items #Removes Headers, Footers, and Blank Items working_items = line_items[5:] #Header working_items = [i for i in working_items if 'Love, Brett' not in i #Footer and i != '' #Blank Items and i != 'IDEAS'] #just don't need print working_items #Reverses list, so oldest entry is first if EXPORT_BACKWARDS: working_items = list(reversed(working_items)) print working_items #Organizes the text, inserting between

tags text = '' for item in working_items: t = '<%s>\n

\n%s\n

\n\n\n' % ( HEADER_VALUE, HEADER_VALUE, item) print t text += t print text #Save File save_name = ideas_email.replace(dir_in, dir_out) save_name = save_name[:-4] + '_p_tag.txt' with open(save_name, 'w') as f: f.write(text) #Final Goodbye print 'IDEAS PROCESSED:\n\t%d\n\t%s\n\t%s' % ( len(working_items), ideas_email, save_name) print 'Script Finished'