mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 15:38:34 +08:00
feat: smtp_proxy_server use httpx (#265)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import httpx
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from twisted.mail import imap4
|
from twisted.mail import imap4
|
||||||
@@ -117,8 +117,9 @@ class SimpleMailbox:
|
|||||||
limit = min(20, end - start + 1) if end and end >= start else 20
|
limit = min(20, end - start + 1) if end and end >= start else 20
|
||||||
if self.message_count > 0 and start > self.message_count:
|
if self.message_count > 0 and start > self.message_count:
|
||||||
return []
|
return []
|
||||||
res = requests.get(
|
res = httpx.get(
|
||||||
f"{settings.proxy_url}/api/mails?limit={limit}&offset={start - 1}", headers={
|
f"{settings.proxy_url}/api/mails?limit={limit}&offset={start - 1}",
|
||||||
|
headers={
|
||||||
"Authorization": f"Bearer {self.password}",
|
"Authorization": f"Bearer {self.password}",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
@@ -139,11 +140,12 @@ class SimpleMailbox:
|
|||||||
def fetchSENT(self, messages):
|
def fetchSENT(self, messages):
|
||||||
start, end = messages.ranges[0]
|
start, end = messages.ranges[0]
|
||||||
start = max(start, 1)
|
start = max(start, 1)
|
||||||
limit = min(20, end - start + 1) if end >= start else 20
|
limit = min(20, end - start + 1) if end and end >= start else 20
|
||||||
if self.message_count > 0 and start > self.message_count:
|
if self.message_count > 0 and start > self.message_count:
|
||||||
return []
|
return []
|
||||||
res = requests.get(
|
res = httpx.get(
|
||||||
f"{settings.proxy_url}/api/sendbox?limit={limit}&offset={start - 1}", headers={
|
f"{settings.proxy_url}/api/sendbox?limit={limit}&offset={start - 1}",
|
||||||
|
headers={
|
||||||
"Authorization": f"Bearer {self.password}",
|
"Authorization": f"Bearer {self.password}",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ aiosmtpd==1.4.6
|
|||||||
pydantic-settings==2.2.1
|
pydantic-settings==2.2.1
|
||||||
requests==2.32.0
|
requests==2.32.0
|
||||||
twisted==24.3.0
|
twisted==24.3.0
|
||||||
|
httpx==0.27.0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import email
|
import email
|
||||||
import requests
|
import httpx
|
||||||
|
|
||||||
from aiosmtpd.controller import Controller
|
from aiosmtpd.controller import Controller
|
||||||
from aiosmtpd.smtp import SMTP, Session, Envelope, AuthResult, LoginPassword
|
from aiosmtpd.smtp import SMTP, Session, Envelope, AuthResult, LoginPassword
|
||||||
@@ -102,7 +102,7 @@ class CustomSMTPHandler:
|
|||||||
}
|
}
|
||||||
_logger.info(f"Send mail {dict(send_body, token='***')}")
|
_logger.info(f"Send mail {dict(send_body, token='***')}")
|
||||||
try:
|
try:
|
||||||
res = requests.post(
|
res = httpx.post(
|
||||||
f"{settings.proxy_url}/external/api/send_mail",
|
f"{settings.proxy_url}/external/api/send_mail",
|
||||||
json=send_body, headers={
|
json=send_body, headers={
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
|
|||||||
Reference in New Issue
Block a user