async def _format_pull(self, user: str, repo: str, pull: PullRequest) -> str: number = pull["number"] author = pull["author"] or NULL_ACTOR assert number and author subject = (f"[{user}/{repo}] {pull['title']} (#{number})" if self.extended_subject else pull["title"]) thread_info = (user, repo, "pull", str(number)) message_id = f"<{'/'.join(thread_info)}@github.com>" html = pull["bodyHTML"] if self.html else None result = await self._format_email(author.get("name") or author.get("login") or "", author.get("email") or author.get("emailOrNull") or "", isoparse(pull["createdAt"]), subject, pull["body"], message_id, html=html) # Get pull request patches async with self.session.get(f"{pull['url']}.patch") as resp: assert resp.status == 200 for rawtext in REGEX_FROM_SPACE.split(await resp.text())[1:]: unixfrom, text = rawtext.split("\n", 1) commit_sha = unixfrom.split(" ", 1)[0] # Keep headers separate from body so that patch is not mangled # (e.g. if patch contains CRLF, don't convert to LF) headers, body = text.split("\n\n", 1) msg = HeaderParser(policy=self.patch_policy).parsestr(headers) if self.extended_subject: msg_subject = msg["Subject"] del msg["Subject"] msg["Subject"] = REGEX_PATCH.sub( r"[PATCH {}/{}#{}\1]".format(user, repo, number), msg_subject) msg["Message-ID"] = ( f"<{'/'.join(thread_info)}/{commit_sha}@github.com>") msg["In-Reply-To"] = message_id msg["References"] = message_id result += ("\n" + "From " + unixfrom + "\n" + msg.as_string(policy=self.policy) + body) if self.comments == 0: return result return result + "\n".join([ i async for i in self._format_comments( pull["id"], f"Re: {subject}", thread_info) ])
# Send an email! from smtplib import SMTP_SSL from email.parser import HeaderParser # If the e-mail headers are in a file, uncomment these two lines: # with open(messagefile) as fp: # headers = Parser().parse(fp) # This is an email.message.Message! # Or for parsing headers in a string, use: headers = HeaderParser().parsestr("From: [email protected]\n" "To: [email protected]\n" "Subject: Test message\n" "\n" "I love you, you know!\n" "----python..\n") # print(type(headers)) # Just list the process. try: conn = SMTP_SSL('smtp.qq.com', port=465) conn.login("*****@*****.**", "Seven1001") tolist = ["*****@*****.**"] try: conn.sendmail('*****@*****.**', tolist, headers.as_string()) finally: conn.quit() except Exception: print("Catch Exception!") else: print("The mail is sending!")