本文整理汇总了Python中quopri.encodestring函数的典型用法代码示例。如果您正苦于以下问题:Python encodestring函数的具体用法?Python encodestring怎么用?Python encodestring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encodestring函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: prepare_message
def prepare_message(email, recipient, recipients_list):
message = email.message
if email.reference_doctype: # is missing the check for unsubscribe message but will not add as there will be no unsubscribe url
unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient,
email.unsubscribe_method, email.unsubscribe_params)
message = message.replace("<!--unsubscribe url-->", quopri.encodestring(unsubscribe_url))
if email.expose_recipients == "header":
pass
else:
if email.expose_recipients == "footer":
if isinstance(email.show_as_cc, basestring):
email.show_as_cc = email.show_as_cc.split(",")
email_sent_to = [r.recipient for r in recipients_list]
email_sent_cc = ", ".join([e for e in email_sent_to if e in email.show_as_cc])
email_sent_to = ", ".join([e for e in email_sent_to if e not in email.show_as_cc])
if email_sent_cc:
email_sent_message = _("This email was sent to {0} and copied to {1}").format(email_sent_to,email_sent_cc)
else:
email_sent_message = _("This email was sent to {0}").format(email_sent_to)
message = message.replace("<!--cc message-->", quopri.encodestring(email_sent_message))
message = message.replace("<!--recipient-->", recipient)
return message
开发者ID:kressi,项目名称:frappe,代码行数:25,代码来源:queue.py
示例2: body
def body(self, n):
if n not in self.cache['body']:
pid, uid, i, _from = self.coda[n]
url = "/cp/ps/Mail/commands/LoadMessage?"
full_url = url + self.params +'&'+ urllib.urlencode( {
'pid':pid,
'uid':uid,
'an':'DefaultMailAccount',
'fp':'inbox',
} )
self.get ( self.baseurl, full_url)
url = "/cp/MailMessageBody.jsp?"
full_url = url + urllib.urlencode( {
'pid' : pid,
'th' : self.token_hash,
} )
_body = self.filter_message( self.get ( self.baseurl, full_url) )
_top = self.top(n)
boundary = self.boundary(_top)
if boundary:
_body = "\r\n\r\n\r\n--" + boundary + "\r\nContent-Type: text/html; charset=UTF-8\r\n"+\
"Content-Transfer-Encoding: quoted-printable\r\n\r\n" + quopri.encodestring(_body.strip(' \r\n')) + \
"\r\n\r\n--" + boundary + "--\r\n"
else:
_body = "\r\n\r\n" + quopri.encodestring( _body.strip(' \r\n') ) + "\r\n\r\n"
self.cache['body'][n] = _body
return self.cache['body'][n]
开发者ID:gbinside,项目名称:pypopper_libero,代码行数:30,代码来源:pypopper_libero.py
示例3: prepare_message
def prepare_message(email, recipient, recipients_list):
message = email.message
if not message:
return ""
if email.add_unsubscribe_link and email.reference_doctype: # is missing the check for unsubscribe message but will not add as there will be no unsubscribe url
unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient,
email.unsubscribe_method, email.unsubscribe_params)
message = message.replace("<!--unsubscribe url-->", quopri.encodestring(unsubscribe_url.encode()).decode())
if email.expose_recipients == "header":
pass
else:
if email.expose_recipients == "footer":
if isinstance(email.show_as_cc, string_types):
email.show_as_cc = email.show_as_cc.split(",")
email_sent_to = [r.recipient for r in recipients_list]
email_sent_cc = ", ".join([e for e in email_sent_to if e in email.show_as_cc])
email_sent_to = ", ".join([e for e in email_sent_to if e not in email.show_as_cc])
if email_sent_cc:
email_sent_message = _("This email was sent to {0} and copied to {1}").format(email_sent_to,email_sent_cc)
else:
email_sent_message = _("This email was sent to {0}").format(email_sent_to)
message = message.replace("<!--cc message-->", quopri.encodestring(email_sent_message.encode()).decode())
message = message.replace("<!--recipient-->", recipient)
message = (message and message.encode('utf8')) or ''
if not email.attachments:
return message
# On-demand attachments
from email.parser import Parser
msg_obj = Parser().parsestr(message)
attachments = json.loads(email.attachments)
for attachment in attachments:
if attachment.get('fcontent'): continue
fid = attachment.get("fid")
if fid:
fname, fcontent = get_file(fid)
attachment.update({
'fname': fname,
'fcontent': fcontent,
'parent': msg_obj
})
attachment.pop("fid", None)
add_attachment(**attachment)
elif attachment.get("print_format_attachment") == 1:
attachment.pop("print_format_attachment", None)
print_format_file = frappe.attach_print(**attachment)
print_format_file.update({"parent": msg_obj})
add_attachment(**print_format_file)
return msg_obj.as_string()
开发者ID:kalisetti,项目名称:frappe,代码行数:59,代码来源:queue.py
示例4: allow_write_by_path
def allow_write_by_path(self, path, userpath, context):
logger.debug("allow_write_by_path " + userpath)
try:
uid, guid, pid = context
response = self.send("BEGIN")
if not response.startswith("OK"):
return True
userpathdir, userpathbase = os.path.split(userpath)
opid = response.split()[1]
response = self.send("SETPROP " + opid + " filename=" + quopri.encodestring(userpathbase))
if not response.startswith("OK"):
return True
response = self.send("SETPROP " + opid + " destination=" + quopri.encodestring(userpath))
if not response.startswith("OK"):
return True
response = self.send("SETPROP " + opid + " burn_after_reading=true")
if not response.startswith("OK"):
return True
user_tuple = pwd.getpwuid(uid)
username = user_tuple.pw_name
response = self.send("SETPROP " + opid + " user=" + username.strip())
if not response.startswith("OK"):
return True
response = self.send("PUSHFILE " + opid + " " + quopri.encodestring(path))
if not response.startswith("OK"):
return True
response = self.send("END " + opid)
if not response.startswith("OK"):
return True
response = self.send("ACLQ " + opid)
if not response.startswith("OK"):
return True
self.send("DESTROY " + opid)
print response.split()[1]
if response.split()[1] == "block":
return False
else:
return True
except (IOError, OSError) as why:
logger.error("allow_write_by_path " + str(why) )
开发者ID:johntwillis,项目名称:mydlp-endpoint-linux,代码行数:48,代码来源:mydlpfilterfs.py
示例5: build_description
def build_description(doc, display):
desc_part = email.Message.Message()
desc_part.set_type("text/html")
desc_part.add_header("Content-Transfer-Encoding", "quoted-printable")
desc_part.set_payload(quopri.encodestring('<html><body bgcolor="%s">' % STANDARD_BACKGROUND_COLOR +
display.encode('UTF-8') + "</body></html>\n"), "UTF-8")
return desc_part
开发者ID:project-renard-survey,项目名称:xerox-parc-uplib-mirror,代码行数:7,代码来源:uplibBinding.py
示例6: encode_string
def encode_string(encoding, data):
encoded = data
if encoding == "base64":
encoded = base64.encodestring(data)
elif encoding == "quoted-printable":
encoded = quopri.encodestring(data)
return encoded.decode("ascii")
开发者ID:lorenzogil,项目名称:pyramid_mailer,代码行数:7,代码来源:response.py
示例7: set_body
def set_body(self, value, content_type):
"""The the body of the message."""
encode = True
if type(value) is unicode:
# see if it is plain ascii first
try:
value = value.encode('us-ascii')
encode = False
except:
value = value.encode('utf-8')
content_type += "; charset='utf-8'"
else:
value = str(value)
self['Content-Type'] = content_type
if encode:
# use the shortest of quoted-printable and base64 encodings
qp = quopri.encodestring(value)
b64 = base64.b64encode(value)
if len(qp) <= len(b64):
self.body = qp
self['Content-Transfer-Encoding'] = 'quoted-printable'
else:
self.body = b64
self['Content-Transfer-Encoding'] = 'base64'
else:
self.body = value
开发者ID:dpw,项目名称:pnntprss,代码行数:28,代码来源:message.py
示例8: mimetextpatch
def mimetextpatch(s, subtype='plain', display=False):
'''If patch in utf-8 transfer-encode it.'''
enc = None
for line in s.splitlines():
if len(line) > 950:
s = quopri.encodestring(s)
enc = "quoted-printable"
break
cs = 'us-ascii'
if not display:
try:
s.decode('us-ascii')
except UnicodeDecodeError:
try:
s.decode('utf-8')
cs = 'utf-8'
except UnicodeDecodeError:
# We'll go with us-ascii as a fallback.
pass
msg = email.MIMEText.MIMEText(s, subtype, cs)
if enc:
del msg['Content-Transfer-Encoding']
msg['Content-Transfer-Encoding'] = enc
return msg
开发者ID:Frostman,项目名称:intellij-community,代码行数:27,代码来源:mail.py
示例9: to_quoted_printable
def to_quoted_printable(fi):
"""
Encode selected region into quoted printable text
"""
offset = fi.getSelectionOffset()
length = fi.getSelectionLength()
if (length > 0):
data = fi.getSelection()
orig = list(fi.getDocument())
orig_len = len(orig)
encoded = list(quopri.encodestring(data))
final_size = len(encoded)
newdata = orig[:offset]
newdata.extend(encoded)
newdata.extend(orig[offset + length:])
fi.newDocument("New file", 1)
fi.setDocument("".join(newdata))
fi.setBookmark(offset, final_size, hex(offset), "#c8ffff")
if (length == 1):
print "Encoded one byte into quoted printable text from offset %s to %s." % (hex(offset), hex(offset))
else:
print "Encoded %s bytes into quoted printable text from offset %s to %s." % (length, hex(offset), hex(offset + length - 1))
开发者ID:nmantani,项目名称:FileInsight-plugins,代码行数:27,代码来源:encoding_ops.py
示例10: encode_transfer_encoding
def encode_transfer_encoding(encoding, body):
if encoding == 'quoted-printable':
return quopri.encodestring(body, quotetabs=False)
elif encoding == 'base64':
return email.encoders._bencode(body)
else:
return body
开发者ID:nylas,项目名称:flanker,代码行数:7,代码来源:part.py
示例11: _flatten_bytestring
def _flatten_bytestring(self, obj):
if PY2:
try:
return obj.decode('utf-8')
except:
pass
return {tags.BYTES: quopri.encodestring(obj).decode('utf-8')}
开发者ID:00gavin,项目名称:music21,代码行数:7,代码来源:pickler.py
示例12: handleOutgoingMail
def handleOutgoingMail (ctx, mail):
#imprime(mail)
uri = __aps__['uri']
if uri:
found = None
for line in mail.head:
if line.lower ().startswith ('list-unsubscribe:'):
found = line
break
if found is None:
# Tentando extrair link embutido na newsletter
if mail.body is not None:
soup = BeautifulSoup(quopri.decodestring(mail.body), "html.parser")
linkSair = soup.find('a',id='linkUnsubscribe')
if linkSair is not None:
if linkSair['href'].lower().find("form.do") != -1:
novoLink = linkSair['href']
else:
# Substituindo link pelo mnemônico, a fim de permitir reconhecimento em alguns leitores de e-mails
novoLink = (uri % linkSair['href'][linkSair['href'].lower().find("uid=")+4:])
er = re.compile(r"<a[^<]*linkUnsubscribe.*?>",re.IGNORECASE|re.DOTALL)
linkInserido = quopri.decodestring(re.search(er,mail.body).group())
erStyle = re.compile(r"(style=.*?)[a-z].=",re.IGNORECASE|re.DOTALL)
styleAdd = re.search(erStyle,linkInserido).group(1) if re.search(erStyle,linkInserido) else ""
mail.body = re.sub(er,quopri.encodestring(("<a %s href=%s>" % (styleAdd,novoLink))),mail.body)
mail.head.append ('List-Unsubscribe: <%s>' % novoLink)
#imprime(mail)
return
开发者ID:estevao90,项目名称:openemm,代码行数:32,代码来源:listUnsubscribeHeader.py
示例13: test_encoding_multipart_quopri
def test_encoding_multipart_quopri(self):
import quopri
from email.mime import multipart
from email.mime import nonmultipart
from repoze.sendmail._compat import b
latin_1_encoded = b('LaPe\xf1a')
latin_1 = latin_1_encoded.decode('latin_1')
plain_string = 'I know what you did last ' + latin_1
message = multipart.MIMEMultipart('alternative')
plain_part = nonmultipart.MIMENonMultipart('plain', 'plain')
plain_part.set_payload(plain_string)
message.attach(plain_part)
html_string = '<p>' + plain_string + '</p>'
html_part = nonmultipart.MIMENonMultipart('text', 'html')
html_part.set_payload(html_string)
message.attach(html_part)
encoded = self._callFUT(message)
self.assertEqual(
encoded.count(quopri.encodestring(plain_string.encode('latin_1'))),
2)
开发者ID:SalesSeek,项目名称:repoze.sendmail,代码行数:26,代码来源:test_encoding.py
示例14: encodeKey
def encodeKey(key):
"""
Encode the key like 'Quoted Printable'.
"""
# According to the memcached's protocol.txt, the key cannot contain
# control characters and white spaces.
return encodestring(key, True).replace('\n', '').replace('\r', '')
开发者ID:Verde1705,项目名称:erp5,代码行数:7,代码来源:MemcachedTool.py
示例15: encode_transfer_encoding
def encode_transfer_encoding(encoding, body):
if encoding == "quoted-printable":
return quopri.encodestring(body)
elif encoding == "base64":
return base64.b64encode(body)
else:
return body
开发者ID:redtailtech,项目名称:flanker,代码行数:7,代码来源:part.py
示例16: encode_string
def encode_string(encoding, data):
encoded = data
if encoding == 'base64':
encoded = base64.encodestring(data)
elif encoding == 'quoted-printable':
encoded = quopri.encodestring(data)
return encoded
开发者ID:lud4ik,项目名称:pyramid_mailer,代码行数:7,代码来源:response.py
示例17: make_replay_response
def make_replay_response(cls, response):
"""
Converts real response to replay_response dict which can be saved
and/or used to initialize a ReplayHTTPResponse.
"""
replay_response = {}
body = response.read() # undecoded byte string
# Add body to replay_response, either as quoted printable for
# text responses or base64 for binary responses.
if response.getheader('content-type', '') \
.startswith(cls.__text_content_types):
if response.getheader('content-encoding') in ['gzip', 'deflate']:
# http://stackoverflow.com/questions/2695152
body = zlib.decompress(body, 16 + zlib.MAX_WBITS)
del response.msg['content-encoding']
# decompression changes the length
if 'content-length' in response.msg:
response.msg['content-length'] = str(len(body))
replay_response['body_quoted_printable'] = quopri.encodestring(body)
else:
replay_response['body'] = body.encode('base64')
replay_response.update(dict(
status=dict(code=response.status, message=response.reason),
headers=dict(response.getheaders())))
return replay_response
开发者ID:Aypak,项目名称:ka-lite,代码行数:27,代码来源:base.py
示例18: test_encoding_latin_1_body
def test_encoding_latin_1_body(self):
body = 'I know what you did last '+self.latin_1
self.message.set_payload(body)
encoded = self.encode()
self.assertTrue(quopri.encodestring(body.encode('latin_1')) in encoded)
开发者ID:hellp,项目名称:repoze.sendmail,代码行数:7,代码来源:test_encoding.py
示例19: encode_string
def encode_string(encoding, data):
encoded = data
if encoding == 'base64':
encoded = base64_encodebytes(data).decode('ascii')
elif encoding == 'quoted-printable':
encoded = quopri.encodestring(data).decode('ascii')
return encoded
开发者ID:ccomb,项目名称:pyramid_mailer,代码行数:7,代码来源:response.py
示例20: _encode_quopri
def _encode_quopri(msg):
"""Own version of quopri isntead of email.encoders.quopri which seems to
be buggy in python3"""
orig = msg.get_payload()
encdata = quopri.encodestring(orig, quotetabs=True)
encdata.replace(b' ', b'=20')
msg.set_payload(encdata.decode('ascii', 'surrogateescape'))
msg['Content-Transfer-Encoding'] = 'quoted-printable'
开发者ID:335969568,项目名称:Blink-1,代码行数:8,代码来源:mhtml_generator.py
注:本文中的quopri.encodestring函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论