mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-07 16:37:04 +08:00
fix: smtp_proxy: cannot decode 8bit && tg bot new random address (#242)
This commit is contained in:
@@ -51,6 +51,9 @@ class SimpleMessage:
|
|||||||
def getFlags(self):
|
def getFlags(self):
|
||||||
return ["\\Seen"]
|
return ["\\Seen"]
|
||||||
|
|
||||||
|
def getInternalDate(self):
|
||||||
|
return self.email.headers.get("Date", "Mon, 1 Jan 1900 00:00:00 +0000")
|
||||||
|
|
||||||
|
|
||||||
@implementer(imap4.IMailboxInfo, imap4.IMailbox)
|
@implementer(imap4.IMailboxInfo, imap4.IMailbox)
|
||||||
class SimpleMailbox:
|
class SimpleMailbox:
|
||||||
@@ -129,7 +132,7 @@ class SimpleMailbox:
|
|||||||
|
|
||||||
def store(self, messages, flags, mode, uid):
|
def store(self, messages, flags, mode, uid):
|
||||||
# IMailboxIMAP.store
|
# IMailboxIMAP.store
|
||||||
pass
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Account(imap4.MemoryAccount):
|
class Account(imap4.MemoryAccount):
|
||||||
@@ -141,7 +144,7 @@ class Account(imap4.MemoryAccount):
|
|||||||
def _emptyMailbox(self, name, id):
|
def _emptyMailbox(self, name, id):
|
||||||
_logger.info(f"New mailbox: {name}, {id}")
|
_logger.info(f"New mailbox: {name}, {id}")
|
||||||
if name != "INBOX":
|
if name != "INBOX":
|
||||||
raise imap4.NoSuchMailbox(name)
|
raise Exception("Mailbox not found")
|
||||||
return SimpleMailbox(self.password)
|
return SimpleMailbox(self.password)
|
||||||
|
|
||||||
def select(self, name, rw=1):
|
def select(self, name, rw=1):
|
||||||
|
|||||||
@@ -41,20 +41,33 @@ class CustomSMTPHandler:
|
|||||||
for part in msg.walk():
|
for part in msg.walk():
|
||||||
content_type = part.get_content_type()
|
content_type = part.get_content_type()
|
||||||
charset = part.get_content_charset()
|
charset = part.get_content_charset()
|
||||||
payload = part.get_payload(decode=True)
|
cte = str(part.get('content-transfer-encoding', '')).lower()
|
||||||
if content_type not in ["text/plain", "text/html"]:
|
if content_type not in ["text/plain", "text/html"]:
|
||||||
_logger.warning(f"Skipping {content_type}")
|
_logger.warning(f"Skipping {content_type}")
|
||||||
continue
|
continue
|
||||||
if not payload:
|
if cte == "8bit":
|
||||||
|
value = part.get_payload(decode=False)
|
||||||
|
else:
|
||||||
|
payload = part.get_payload(decode=True)
|
||||||
|
value = payload.decode(charset) if charset else payload
|
||||||
|
if not value:
|
||||||
continue
|
continue
|
||||||
content_list.append({
|
content_list.append({
|
||||||
"type": content_type,
|
"type": content_type,
|
||||||
"value": payload.decode(charset)
|
"value": value
|
||||||
})
|
})
|
||||||
elif msg.get_content_type() in ["text/plain", "text/html"] and msg.get_payload(decode=True):
|
elif msg.get_content_type() in ["text/plain", "text/html"] and msg.get_payload(decode=True):
|
||||||
|
cte = str(msg.get('content-transfer-encoding', '')).lower()
|
||||||
|
charset = msg.get_content_charset()
|
||||||
|
if cte == "8bit":
|
||||||
|
value = msg.get_payload(decode=False)
|
||||||
|
else:
|
||||||
|
payload = msg.get_payload(decode=True)
|
||||||
|
value = payload.decode(charset) if charset else payload
|
||||||
|
_logger.info(f"Payload {msg._payload} charset {charset}")
|
||||||
content_list.append({
|
content_list.append({
|
||||||
"type": msg.get_content_type(),
|
"type": msg.get_content_type(),
|
||||||
"value": msg.get_payload(decode=True).decode()
|
"value": value
|
||||||
})
|
})
|
||||||
|
|
||||||
if not content_list:
|
if not content_list:
|
||||||
|
|||||||
@@ -61,11 +61,16 @@ export function newTelegramBot(c: Context, token: string): Telegraf {
|
|||||||
return await ctx.reply("无法获取用户信息");
|
return await ctx.reply("无法获取用户信息");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
if (c.env.RATE_LIMITER) {
|
||||||
const address = ctx?.message?.text.slice("/new".length).trim();
|
const { success } = await c.env.RATE_LIMITER.limit(
|
||||||
if (!address) {
|
{ key: `${CONSTANTS.TG_KV_PREFIX}:${userId}` }
|
||||||
return await ctx.reply("请输入邮箱地址");
|
)
|
||||||
|
if (!success) {
|
||||||
|
return await ctx.reply("操作过于频繁");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
const address = ctx?.message?.text.slice("/new".length).trim() || Math.random().toString(36).substring(2, 15);
|
||||||
const [name, domain] = address.includes("@") ? address.split("@") : [address, null];
|
const [name, domain] = address.includes("@") ? address.split("@") : [address, null];
|
||||||
const jwtList = await c.env.KV.get(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, { type: 'json' }) || [];
|
const jwtList = await c.env.KV.get(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, { type: 'json' }) || [];
|
||||||
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user