def saveattachments(formmaxattach= savedir=savedir)""save uploaded attachment files in local files on server from which mailtools will add to mailthe fieldstorage parser and other parts of cgi module can fail for many upload typesso we don' try very hard to handle unicode encodings here""partnames [for in range( maxattach+ )fieldname 'attach%di if fieldname in form and form[fieldnamefilenamefileinfo form[fieldnamesent and filledfiledata fileinfo value read into string filename fileinfo filename client' pathname if '\\in filenamebasename filename split('\\')[- try dos clients elif '/in filenamebasename filename split('/')[- try unix clients elsebasename filename assume dir stripped pathname os path join(savedirbasenameif isinstance(filedatastr) rb needs bytes filedata filedata encode( use encodingsavefile open(pathname'wb'savefile write(filedataor with statement savefile close(but eibti still os chmod(pathname need for some srvrs partnames append(pathnamelist of local paths return partnames gets type from name #commonhtml dumpstatepage( form cgi fieldstorage(attaches saveattachments(formparse form input data cgi print_form(formto see server name from module or get-style url smtpservername commonhtml getstandardsmtpfields(formparms assumed to be in form or url here from commonhtml import getfield from getfield(form'from'to getfield(form'to'cc getfield(form'cc'subj getfield(form'subject'text getfield(form'text'if cc ='?'cc 'fetch value attributes empty fields may not be sent headers encoded per utf within mailtools if non-ascii parser mailtools mailparser(tos parser splitaddresses(tomultiple recip lists',sept ccs (cc and parser splitaddresses(cc)or 'extrahdrs [('cc'ccs)(' -mailer''pymailcgi ') resolve main text and text attachment encodingsdefault=ascii in mailtools the pymailcgi server