102 lines
3.7 KiB
Python
102 lines
3.7 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import requests
|
|
import json
|
|
import os
|
|
import html
|
|
import re
|
|
|
|
# 基础URL
|
|
BASE_URL = "http://localhost:5000/api"
|
|
|
|
def check_mailbox_emails(mailbox_id):
|
|
"""检查特定邮箱的邮件"""
|
|
try:
|
|
# 获取邮箱信息
|
|
mailbox_response = requests.get(f"{BASE_URL}/mailboxes/{mailbox_id}")
|
|
mailbox_data = mailbox_response.json()
|
|
|
|
if not mailbox_data.get('success', False):
|
|
print(f"获取邮箱信息失败: {mailbox_data.get('error', '未知错误')}")
|
|
return
|
|
|
|
mailbox = mailbox_data.get('mailbox', {})
|
|
print(f"邮箱信息: {mailbox.get('full_address')} (ID: {mailbox.get('id')})")
|
|
|
|
# 获取该邮箱的邮件
|
|
emails_response = requests.get(f"{BASE_URL}/mailboxes/{mailbox_id}/emails")
|
|
emails_data = emails_response.json()
|
|
|
|
if not emails_data.get('success', False):
|
|
print(f"获取邮件失败: {emails_data.get('error', '未知错误')}")
|
|
return
|
|
|
|
# 从响应中提取emails列表
|
|
emails = emails_data.get('emails', [])
|
|
print(f"邮件数量: {len(emails)}")
|
|
|
|
# 遍历显示邮件内容
|
|
for i, email in enumerate(emails, 1):
|
|
print(f"\n--- 邮件 {i} ---")
|
|
print(f"ID: {email.get('id', '未知')}")
|
|
print(f"主题: {email.get('subject', '无主题')}")
|
|
print(f"发件人: {email.get('from_addr', '未知')}")
|
|
print(f"接收时间: {email.get('created_at', '未知')}")
|
|
|
|
# 获取邮件详情
|
|
email_id = email.get('id')
|
|
if email_id:
|
|
# 打印完整的邮件信息,包括所有字段
|
|
print("\n邮件详细信息:")
|
|
for key, value in email.items():
|
|
print(f" {key}: {value}")
|
|
|
|
# 尝试提取验证码直接从邮件主题或内容
|
|
email_subject = email.get('subject', '')
|
|
email_body_text = email.get('body_text', '')
|
|
email_body_html = email.get('body_html', '')
|
|
|
|
print("\n邮件正文:")
|
|
if email_body_text:
|
|
print(f"--- 文本内容 ---\n{email_body_text[:200]}...")
|
|
|
|
if email_body_html:
|
|
print(f"--- HTML内容 ---\n{email_body_html[:200]}...")
|
|
|
|
# 尝试从原始内容中提取验证码
|
|
verification_code = None
|
|
# 从HTML内容中查找
|
|
if email_body_html:
|
|
code_match = re.search(r'letter-spacing: 5px[^>]*>([^<]+)<', email_body_html)
|
|
if code_match:
|
|
verification_code = code_match.group(1).strip()
|
|
|
|
# 从文本内容中查找6位数字
|
|
if not verification_code and email_body_text:
|
|
code_match = re.search(r'\b(\d{6})\b', email_body_text)
|
|
if code_match:
|
|
verification_code = code_match.group(1)
|
|
|
|
if verification_code:
|
|
print(f"\n提取到的验证码: {verification_code}")
|
|
else:
|
|
print("\n未能提取到验证码")
|
|
|
|
print("-------------------")
|
|
|
|
if not emails:
|
|
print("此邮箱没有邮件")
|
|
|
|
except Exception as e:
|
|
print(f"查询失败: {str(e)}")
|
|
|
|
def main():
|
|
# 邮箱ID - testaa@nosqli.com 的ID应该是1
|
|
mailbox_id = 1
|
|
|
|
print(f"检查邮箱ID {mailbox_id} 的邮件...")
|
|
check_mailbox_emails(mailbox_id)
|
|
|
|
if __name__ == "__main__":
|
|
main() |