def quotetext(form): """ note that headers come from the prior page's form here, not from parsing the mail message again; that means that commonhtml.viewpage must pass along date as a hidden field """ quoted = '\n-----Original Message-----\n' for hdr in ('From', 'To', 'Date'): quoted = quoted + '%s: %s\n' % (hdr, getfield(form, hdr)) quoted = quoted + '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted
def quotetext(form): """ note that headers come from the prior page's form here, not from parsing the mail message again; that means that commonhtml.viewpage must pass along date as a hidden field """ parser = mailtools.MailParser() addrhdrs = ('From', 'To', 'Cc', 'Bcc') # decode name only quoted = '\n-----Original Message-----\n' for hdr in ('From', 'To', 'Date'): rawhdr = getfield(form, hdr) if hdr not in addrhdrs: dechdr = parser.decodeHeader(rawhdr) # 3.0: decode for display else: # encoded on sends dechdr = parser.decodeAddrHeader(rawhdr) # email names only quoted += '%s: %s\n' % (hdr, dechdr) quoted += '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted
def quotetext(form): """ обратите внимание, что заголовки поступают из формы предыдущей страницы, а не получаются в результате повторного анализа почтового сообщения; это означает, что функция commonhtml.viewpage должна передавать дату в скрытом поле """ parser = mailtools.MailParser() addrhdrs = ('From', 'To', 'Cc', 'Bcc') # декодируется только имя quoted = '\n-----Original Message-----\n' for hdr in ('From', 'To', 'Date'): rawhdr = getfield(form, hdr) if hdr not in addrhdrs: dechdr = parser.decodeHeader( rawhdr) # 3.0: декодировать для отображения else: # закодировать при отправке dechdr = parser.decodeAddrHeader(rawhdr) # только имена в адресах quoted += '%s: %s\n' % (hdr, dechdr) quoted += '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted
dechdr = parser.decodeHeader(rawhdr) # 3.0: decode for display else: # encoded on sends dechdr = parser.decodeAddrHeader(rawhdr) # email names only quoted += '%s: %s\n' % (hdr, dechdr) quoted += '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted form = cgi.FieldStorage() # parse form or URL data user, pswd, site = commonhtml.getstandardpopfields(form) pswd = secret.decode(pswd) try: if form['action'].value == 'Reply': headers = {'From': mailconfig.myaddress, # 3.0: commonhtml decodes 'To': getfield(form, 'From'), 'Cc': mailconfig.myaddress, 'Subject': 'Re: ' + getfield(form, 'Subject')} commonhtml.editpage('Reply', headers, quotetext(form)) elif form['action'].value == 'Forward': headers = {'From': mailconfig.myaddress, # 3.0: commonhtml decodes 'To': '', 'Cc': mailconfig.myaddress, 'Subject': 'Fwd: ' + getfield(form, 'Subject')} commonhtml.editpage('Forward', headers, quotetext(form)) elif form['action'].value == 'Delete': # mnum field is required here msgnum = int(form['mnum'].value) # but not eval(): may be code fetcher = mailtools.SilentMailFetcher(site, user, pswd) fetcher.deleteMessages([msgnum])
savefile.write(filedata) # or a with statement savefile.close() # but EIBTI still os.chmod(pathname, 0o666) # need for some srvrs partnames.append(pathname) # list of local paths return partnames # gets type from name #commonhtml.dumpstatepage(0) form = cgi.FieldStorage() # parse form input data attaches = saveAttachments(form) # cgi.print_form(form) to see # server name from module or get-style URL smtpservername = commonhtml.getstandardsmtpfields(form) # parms assumed to be in form or URL here from commonhtml import getfield # fetch value attributes From = getfield(form, 'From') # empty fields may not be sent To = getfield(form, 'To') Cc = getfield(form, 'Cc') Subj = getfield(form, 'Subject') text = getfield(form, 'text') if Cc == '?': Cc = '' # 3.0: headers encoded per utf8 within mailtools if non-ascii parser = mailtools.MailParser() Tos = parser.splitAddresses(To) # multiple recip lists: ',' sept Ccs = (Cc and parser.splitAddresses(Cc)) or '' extraHdrs = [('Cc', Ccs), ('X-Mailer', 'PyMailCGI 3.0')] # 3.0: resolve main text and text attachment encodings; default=ascii in mailtools bodyencoding = 'ascii' try:
""" quoted = '\n-----Original Message-----\n' for hdr in ('From', 'To', 'Date'): quoted = quoted + '%s: %s\n' % (hdr, getfield(form, hdr)) quoted = quoted + '\n' + getfield(form, 'text') quoted = '\n' + quoted.replace('\n', '\n> ') return quoted form = cgi.FieldStorage() # parse form or url data user, pswd, site = commonhtml.getstandardpopfields(form) pswd = secret.decode(pswd) try: if form['action'].value == 'Reply': headers = {'From': mailconfig.myaddress, 'To': getfield(form, 'From'), 'Cc': mailconfig.myaddress, 'Subject': 'Re: ' + getfield(form, 'Subject')} commonhtml.editpage('Reply', headers, quotetext(form)) elif form['action'].value == 'Forward': headers = {'From': mailconfig.myaddress, 'To': '', 'Cc': mailconfig.myaddress, 'Subject': 'Fwd: ' + getfield(form, 'Subject')} commonhtml.editpage('Forward', headers, quotetext(form)) elif form['action'].value == 'Delete': # mnum field is required here msgnum = int(form['mnum'].value) # but not eval(): may be code fetcher = mailtools.SilentMailFetcher(site, user, pswd) #EXPERIMENTAL
savefile.close() # но EIBTI os.chmod(pathname, 0o666) # требуется некоторыми серверами partnames.append(pathname) # список локальных путей return partnames # определить тип по имени # commonhtml.dumpstatepage(0) form = cgi.FieldStorage() attaches = saveAttachments(form) # cgi.print_form(form), чтобы посмотреть # имя сервера из модуля или из URL, полученного методом GET smtpservername = commonhtml.getstandardsmtpfields(form) # здесь предполагается, что параметры получены из формы или из URL from commonhtml import getfield # для получения значений атрибутов From = getfield(form, 'Form') # пустые поля не должны отправляться To = getfield(form, 'To') Cc = getfield(form, 'Cc') Subj = getfield(form, 'Subject') text = getfield(form, 'text') if Cc == '?': Cc = '' # 3.0: не-ascii заголовки кодируются в utf8 в пакете mailtools parser = mailtools.MailParser() Tos = parser.splitAddresses(To) # списки получателей: разделитель ',' Ccs = (Cc and parser.splitAddresses(Cc)) or '' extraHdrs = [('Cc', Ccs), ('X-Mailer', 'PyMailCGI 3.0')] # 3.0: определить кодировку для основного текста и текстовых вложений; # по умолчанию = ascii в mailtools bodyencoding = 'ascii'