当前位置: 首页>>代码示例>>Python>>正文


Python MIMEImage.set_param方法代码示例

本文整理汇总了Python中email.MIMEImage.MIMEImage.set_param方法的典型用法代码示例。如果您正苦于以下问题:Python MIMEImage.set_param方法的具体用法?Python MIMEImage.set_param怎么用?Python MIMEImage.set_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.MIMEImage.MIMEImage的用法示例。


在下文中一共展示了MIMEImage.set_param方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_feedback

# 需要导入模块: from email.MIMEImage import MIMEImage [as 别名]
# 或者: from email.MIMEImage.MIMEImage import set_param [as 别名]
def handle_feedback():
	userdata = request.get_json(silent=True)
	
	# spamschutz vor Bots, die github durchlesen:
	domain = "."+".".join("de uni-frankfurt physik".split(" ")[::-1])
	from_addr = ("POKAL-Feedback", "[email protected]")
	to_addrs = [
		("eLearning", "[email protected]%s" % domain),
		("POTT", "[email protected]%s" % domain),
	]
	subject = "POKAL Feedback"
	
	# Force python to encode utf-8 as quoted-printable and not base64
	# (both subject and body). unfortunately this modifies a global setting,
	# but email sending in POKAL is not such a popular task yet.
	Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
	
	if userdata:
		# could correctly parse userdata
		output = {'status': 'JSON could be retrieved'}
		output['userdata'] = userdata
		status = 200 # OK
		
		msg = MIMEMultipart()
		msg['From'] = formataddr(from_addr)
		msg['To'] = ", ".join(map(formataddr,to_addrs))
		msg['Date'] = formatdate(localtime=True)
		msg['Subject'] = subject
		msg['Content-Type'] = 'text/html; charset=utf-8'
		
		body = u"""
Ein neuer POKAL-Feedback ist durch das Feedbacksystem (#984) eingereicht worden.

== Vom Besucher ausgefüllter Text ==
$note

== Screenshot ==
[[Image($screenshot_filename, width=100%)]]

== Daten ==

 URL des Worksheets::
    $url
 Name (Titel) des Worksheets::
    ''$worksheet_name''
 HRZ-Username des Benutzers::
    `$username`
 Nickname des Benutzers::
    `$nickname`
 Browser des Benutzers (User Agent)::
    `$HTTP_USER_AGENT`
 IP-Adresse des Besuchers::
    `HTTP_X_FORWARDED_FOR = $HTTP_X_FORWARDED_FOR`
 Verarbeitender POKAL-Server::
    `SERVER_NAME:... = $SERVER_NAME:$SERVER_PORT`
 Zwischenpunkt (Remote IP des bearbeitenden Pokal-Servers)::
    `REMOTE_ADDR = $REMOTE_ADDR`
 Endpunkt POKAL-Host::
    `HTTP_HOST = $HTTP_HOST`
 Uhrzeit::
    $date
 Anzahl Benutzer im Chat::
    $chat_nicknames_count
 Anzahl Chatzeilen::
    $chat_messages_count
 Länge Worksheet (Anzahl Worksheet-Zellen)::
    $cells_count

@type: Designen
@component: POKAL
@keywords: pokal, feedback
@sensitive: 1

"""
		# look at the image
		if "img" in userdata:
			screenshot_filename = "screenshot-%s.png" % str(uuid4())[:6]
			binaryimg = unpack_html2image_screenshot(userdata["img"])
			img_part = MIMEImage(binaryimg)
			img_part.set_param('name', screenshot_filename)
			img_part.add_header('Content-Disposition', 'attachment; filename="%s"' % screenshot_filename)
		else:	screenshot_filename = "<no screenshot present>"
		
		# enrich the data with classical CGI ENV vars
		serverdata = request.environ
		# further data
		furtherdata = {
			"screenshot_filename": screenshot_filename,
			"date": datetime.now().strftime("%c")
		}
		# userdata are overwritten by serverdata
		replace_data = dict(userdata.items() + serverdata.items() + furtherdata.items())
		
		body = Template(body).safe_substitute(replace_data)
		# make sure of a quoted printable body
		msg.attach( MIMEText(body.encode('utf-8'), 'plain', 'utf-8') )
		
		# format the image attachment
		msg.attach(img_part)
		
#.........这里部分代码省略.........
开发者ID:PhysikOnline-FFM,项目名称:sagenb,代码行数:103,代码来源:feedback.py


注:本文中的email.MIMEImage.MIMEImage.set_param方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。