本文整理汇总了Python中r2.models.Message._byID36方法的典型用法代码示例。如果您正苦于以下问题:Python Message._byID36方法的具体用法?Python Message._byID36怎么用?Python Message._byID36使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.Message
的用法示例。
在下文中一共展示了Message._byID36方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_message
# 需要导入模块: from r2.models import Message [as 别名]
# 或者: from r2.models.Message import _byID36 [as 别名]
def process_message(msg):
msg_dict = json.loads(msg.body)
if msg_dict["event"] == "new_message":
message_id36 = msg_dict["message_id36"]
message = Message._byID36(message_id36, data=True)
send_modmail_email(message)
elif msg_dict["event"] == "blocked_muted":
subreddit_id36 = msg_dict["subreddit_id36"]
sr = Subreddit._byID36(subreddit_id36, data=True)
parent_id36 = msg_dict["parent_id36"]
parent = Message._byID36(parent_id36, data=True)
sender_email = msg_dict["sender_email"]
incoming_email_id = msg_dict["incoming_email_id"]
send_blocked_muted_email(sr, parent, sender_email, incoming_email_id)
示例2: POST_zendeskreply
# 需要导入模块: from r2.models import Message [as 别名]
# 或者: from r2.models.Message import _byID36 [as 别名]
def POST_zendeskreply(self):
request_body = request.POST
recipient = request_body["recipient"]
sender_email = request_body["sender"]
from_ = request_body["from"]
subject = request_body["subject"]
body_plain = request_body["body-plain"]
stripped_text = request_body["stripped-text"]
stripped_signature = request_body["stripped-signature"]
timestamp = request_body["timestamp"]
token = request_body["token"]
signature = request_body["signature"]
email_id = request_body["Message-Id"]
if not validate_mailgun_webhook(timestamp, token, signature):
# per Mailgun docs send a 406 so the message won't be retried
abort(406, "invalid signature")
message_id36 = parse_and_validate_reply_to_address(recipient)
if not message_id36:
# per Mailgun docs send a 406 so the message won't be retried
abort(406, "invalid message")
parent = Message._byID36(message_id36, data=True)
to = Account._byID(parent.author_id, data=True)
sr = Subreddit._byID(parent.sr_id, data=True)
body = self.get_snipped_body(stripped_text, stripped_signature)
try:
markdown_souptest(body)
except SoupError:
g.log.warning("bad markdown in modmail email: %s", body)
abort(406, "invalid body")
if parent.get_muted_user_in_conversation():
queue_blocked_muted_email(sr, parent, sender_email, email_id)
return
# keep the subject consistent
message_subject = parent.subject
if not message_subject.startswith("re: "):
message_subject = "re: " + message_subject
# from_ is like '"NAME (GROUP)" <[email protected]>'
match = re.search("\"(?P<name>\w+) [\w ()]*\"", from_)
from_sr = True
author = Account.system_user()
if match and match.group("name") in g.live_config['modmail_account_map']:
zendesk_name = match.group("name")
moderator_name = g.live_config['modmail_account_map'][zendesk_name]
moderator = Account._by_name(moderator_name)
if sr.is_moderator_with_perms(moderator, "mail"):
author = moderator
from_sr = False
message, inbox_rel = Message._new(
author=author,
to=to,
subject=message_subject,
body=body,
ip='0.0.0.0',
parent=parent,
sr=sr,
from_sr=from_sr,
can_send_email=False,
sent_via_email=True,
email_id=email_id,
)
message._commit()
queries.new_message(message, inbox_rel)
g.stats.simple_event("mailgun.incoming.success")
g.stats.simple_event("modmail_email.incoming_email")