""save fetched email' parts to files on server to be viewed in user' web browser ""import os if not os path exists(savedir)in cgi script' cwd on server os mkdir(savedirwill open per your browser for filename in os listdir(savedir)clean up last messagetempdirpath os path join(savedirfilenameos remove(dirpathtypesandnames parser saveparts(savedirmessagefilenames [fname for (ctypefnamein typesandnamesfor filename in filenamesos chmod(filename some srvrs may need read/write return filenames form cgi fieldstorage(userpswdsite commonhtml getstandardpopfields(formpswd secret decode(pswdtrymsgnum form['mnum'value parser mailtools mailparser(fetcher mailtools silentmailfetcher(siteuserpswdfulltext fetcher downloadmessage(int(msgnum)message parser parsemessage(fulltextparts saveattachments(messageparsermtypecontent parser findmaintext(messagecommonhtml viewpage(msgnummessagecontentformpartsexceptcommonhtml errorpage('error loading message'from url link don' evalemail pkg message for url links first txt part encoded pswd againmuch of the work here happens in the commonhtml modulelisted later in this section (see example - this script adds logic to decode the input password (using the configurable secret encryption moduleand extract the selected mail' headers and text using the mailtools module package from again the full text of the selected message is ultimately fetchedparsedand decoded by mailtoolsusing the standard library' poplib module and email package although we'll have to refetch this message if viewed againversion and later do not grab all mails to get just the one selected +also new in version the saveattachments function in this script splits off the parts of fetched message and stores them in directory on the web server machine this was discussed earlier in this -the view page is then augmented with url links that point at the saved part files your web browser will open them according to their filenames and content all the work of part extractiondecodingand naming is +notice that the message number arrives as string and must be converted to an integer in order to be used to fetch the message but we're careful not to convert with eval heresince this is string passed over the net and could have arrived embedded at the end of an arbitrary url (remember that earlier warning? the pymailcgi server