tempemail-sdk 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. tempemail_sdk-1.1.0/PKG-INFO +86 -0
  2. tempemail_sdk-1.1.0/README.md +75 -0
  3. tempemail_sdk-1.1.0/pyproject.toml +22 -0
  4. tempemail_sdk-1.1.0/setup.cfg +4 -0
  5. tempemail_sdk-1.1.0/tempemail_sdk.egg-info/PKG-INFO +86 -0
  6. tempemail_sdk-1.1.0/tempemail_sdk.egg-info/SOURCES.txt +25 -0
  7. tempemail_sdk-1.1.0/tempemail_sdk.egg-info/dependency_links.txt +1 -0
  8. tempemail_sdk-1.1.0/tempemail_sdk.egg-info/requires.txt +4 -0
  9. tempemail_sdk-1.1.0/tempemail_sdk.egg-info/top_level.txt +1 -0
  10. tempemail_sdk-1.1.0/tempmail_sdk/__init__.py +53 -0
  11. tempemail_sdk-1.1.0/tempmail_sdk/client.py +235 -0
  12. tempemail_sdk-1.1.0/tempmail_sdk/logger.py +54 -0
  13. tempemail_sdk-1.1.0/tempmail_sdk/normalize.py +144 -0
  14. tempemail_sdk-1.1.0/tempmail_sdk/providers/__init__.py +3 -0
  15. tempemail_sdk-1.1.0/tempmail_sdk/providers/awamail.py +81 -0
  16. tempemail_sdk-1.1.0/tempmail_sdk/providers/chatgpt_org_uk.py +58 -0
  17. tempemail_sdk-1.1.0/tempmail_sdk/providers/dropmail.py +76 -0
  18. tempemail_sdk-1.1.0/tempmail_sdk/providers/guerrillamail.py +67 -0
  19. tempemail_sdk-1.1.0/tempmail_sdk/providers/linshi_email.py +63 -0
  20. tempemail_sdk-1.1.0/tempmail_sdk/providers/mail_tm.py +157 -0
  21. tempemail_sdk-1.1.0/tempmail_sdk/providers/maildrop.py +155 -0
  22. tempemail_sdk-1.1.0/tempmail_sdk/providers/temp_mail_io.py +88 -0
  23. tempemail_sdk-1.1.0/tempmail_sdk/providers/tempmail.py +60 -0
  24. tempemail_sdk-1.1.0/tempmail_sdk/providers/tempmail_la.py +85 -0
  25. tempemail_sdk-1.1.0/tempmail_sdk/providers/tempmail_lol.py +56 -0
  26. tempemail_sdk-1.1.0/tempmail_sdk/retry.py +83 -0
  27. tempemail_sdk-1.1.0/tempmail_sdk/types.py +106 -0
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: tempemail-sdk
3
+ Version: 1.1.0
4
+ Summary: 临时邮箱 SDK,支持 11 个邮箱服务提供商,所有渠道返回统一标准化格式
5
+ License: GPL-3.0
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.28.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=7.0; extra == "dev"
11
+
12
+ # tempmail-sdk (Python)
13
+
14
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
15
+
16
+ 临时邮箱 SDK(Python),支持 11 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install tempmail-sdk
22
+ ```
23
+
24
+ ## 支持的渠道
25
+
26
+ | 渠道 | 服务商 | 需要 Token | 说明 |
27
+ |------|--------|:----------:|------|
28
+ | `tempmail` | tempmail.ing | - | 支持自定义有效期 |
29
+ | `linshi-email` | linshi-email.com | - | |
30
+ | `tempmail-lol` | tempmail.lol | ✅ | 支持指定域名 |
31
+ | `chatgpt-org-uk` | mail.chatgpt.org.uk | - | |
32
+ | `tempmail-la` | tempmail.la | - | 支持分页 |
33
+ | `temp-mail-io` | temp-mail.io | - | |
34
+ | `awamail` | awamail.com | ✅ | Session Cookie 自动管理 |
35
+ | `mail-tm` | mail.tm | ✅ | 自动注册账号获取 Bearer Token |
36
+ | `dropmail` | dropmail.me | ✅ | GraphQL API |
37
+ | `guerrillamail` | guerrillamail.com | ✅ | 公开 JSON API |
38
+ | `maildrop` | maildrop.cc | ✅ | GraphQL API,自带反垃圾 |
39
+
40
+ ## 快速开始
41
+
42
+ ```python
43
+ from tempmail_sdk import generate_email, get_emails, GenerateEmailOptions, GetEmailsOptions
44
+
45
+ # 创建临时邮箱
46
+ info = generate_email(GenerateEmailOptions(channel="guerrillamail"))
47
+ print(f"邮箱: {info.email}")
48
+
49
+ # 获取邮件
50
+ result = get_emails(GetEmailsOptions(
51
+ channel=info.channel,
52
+ email=info.email,
53
+ token=info.token,
54
+ ))
55
+ if result.success:
56
+ print(f"收到 {len(result.emails)} 封邮件")
57
+ ```
58
+
59
+ ## 使用客户端类
60
+
61
+ ```python
62
+ from tempmail_sdk import TempEmailClient, GenerateEmailOptions
63
+
64
+ client = TempEmailClient()
65
+ info = client.generate(GenerateEmailOptions(channel="maildrop"))
66
+ result = client.get_emails()
67
+ ```
68
+
69
+ ## 日志
70
+
71
+ ```python
72
+ from tempmail_sdk import set_log_level, LOG_DEBUG
73
+
74
+ set_log_level(LOG_DEBUG) # 开启所有日志
75
+ ```
76
+
77
+ ## 重试配置
78
+
79
+ ```python
80
+ from tempmail_sdk import generate_email, GenerateEmailOptions, RetryConfig
81
+
82
+ info = generate_email(GenerateEmailOptions(
83
+ channel="temp-mail-io",
84
+ retry=RetryConfig(max_retries=3, initial_delay=2.0),
85
+ ))
86
+ ```
@@ -0,0 +1,75 @@
1
+ # tempmail-sdk (Python)
2
+
3
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
4
+
5
+ 临时邮箱 SDK(Python),支持 11 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install tempmail-sdk
11
+ ```
12
+
13
+ ## 支持的渠道
14
+
15
+ | 渠道 | 服务商 | 需要 Token | 说明 |
16
+ |------|--------|:----------:|------|
17
+ | `tempmail` | tempmail.ing | - | 支持自定义有效期 |
18
+ | `linshi-email` | linshi-email.com | - | |
19
+ | `tempmail-lol` | tempmail.lol | ✅ | 支持指定域名 |
20
+ | `chatgpt-org-uk` | mail.chatgpt.org.uk | - | |
21
+ | `tempmail-la` | tempmail.la | - | 支持分页 |
22
+ | `temp-mail-io` | temp-mail.io | - | |
23
+ | `awamail` | awamail.com | ✅ | Session Cookie 自动管理 |
24
+ | `mail-tm` | mail.tm | ✅ | 自动注册账号获取 Bearer Token |
25
+ | `dropmail` | dropmail.me | ✅ | GraphQL API |
26
+ | `guerrillamail` | guerrillamail.com | ✅ | 公开 JSON API |
27
+ | `maildrop` | maildrop.cc | ✅ | GraphQL API,自带反垃圾 |
28
+
29
+ ## 快速开始
30
+
31
+ ```python
32
+ from tempmail_sdk import generate_email, get_emails, GenerateEmailOptions, GetEmailsOptions
33
+
34
+ # 创建临时邮箱
35
+ info = generate_email(GenerateEmailOptions(channel="guerrillamail"))
36
+ print(f"邮箱: {info.email}")
37
+
38
+ # 获取邮件
39
+ result = get_emails(GetEmailsOptions(
40
+ channel=info.channel,
41
+ email=info.email,
42
+ token=info.token,
43
+ ))
44
+ if result.success:
45
+ print(f"收到 {len(result.emails)} 封邮件")
46
+ ```
47
+
48
+ ## 使用客户端类
49
+
50
+ ```python
51
+ from tempmail_sdk import TempEmailClient, GenerateEmailOptions
52
+
53
+ client = TempEmailClient()
54
+ info = client.generate(GenerateEmailOptions(channel="maildrop"))
55
+ result = client.get_emails()
56
+ ```
57
+
58
+ ## 日志
59
+
60
+ ```python
61
+ from tempmail_sdk import set_log_level, LOG_DEBUG
62
+
63
+ set_log_level(LOG_DEBUG) # 开启所有日志
64
+ ```
65
+
66
+ ## 重试配置
67
+
68
+ ```python
69
+ from tempmail_sdk import generate_email, GenerateEmailOptions, RetryConfig
70
+
71
+ info = generate_email(GenerateEmailOptions(
72
+ channel="temp-mail-io",
73
+ retry=RetryConfig(max_retries=3, initial_delay=2.0),
74
+ ))
75
+ ```
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tempemail-sdk"
7
+ version = "1.1.0"
8
+ description = "临时邮箱 SDK,支持 11 个邮箱服务提供商,所有渠道返回统一标准化格式"
9
+ readme = "README.md"
10
+ license = {text = "GPL-3.0"}
11
+ requires-python = ">=3.8"
12
+ dependencies = [
13
+ "requests>=2.28.0",
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ dev = [
18
+ "pytest>=7.0",
19
+ ]
20
+
21
+ [tool.setuptools.packages.find]
22
+ include = ["tempmail_sdk*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: tempemail-sdk
3
+ Version: 1.1.0
4
+ Summary: 临时邮箱 SDK,支持 11 个邮箱服务提供商,所有渠道返回统一标准化格式
5
+ License: GPL-3.0
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.28.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=7.0; extra == "dev"
11
+
12
+ # tempmail-sdk (Python)
13
+
14
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
15
+
16
+ 临时邮箱 SDK(Python),支持 11 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pip install tempmail-sdk
22
+ ```
23
+
24
+ ## 支持的渠道
25
+
26
+ | 渠道 | 服务商 | 需要 Token | 说明 |
27
+ |------|--------|:----------:|------|
28
+ | `tempmail` | tempmail.ing | - | 支持自定义有效期 |
29
+ | `linshi-email` | linshi-email.com | - | |
30
+ | `tempmail-lol` | tempmail.lol | ✅ | 支持指定域名 |
31
+ | `chatgpt-org-uk` | mail.chatgpt.org.uk | - | |
32
+ | `tempmail-la` | tempmail.la | - | 支持分页 |
33
+ | `temp-mail-io` | temp-mail.io | - | |
34
+ | `awamail` | awamail.com | ✅ | Session Cookie 自动管理 |
35
+ | `mail-tm` | mail.tm | ✅ | 自动注册账号获取 Bearer Token |
36
+ | `dropmail` | dropmail.me | ✅ | GraphQL API |
37
+ | `guerrillamail` | guerrillamail.com | ✅ | 公开 JSON API |
38
+ | `maildrop` | maildrop.cc | ✅ | GraphQL API,自带反垃圾 |
39
+
40
+ ## 快速开始
41
+
42
+ ```python
43
+ from tempmail_sdk import generate_email, get_emails, GenerateEmailOptions, GetEmailsOptions
44
+
45
+ # 创建临时邮箱
46
+ info = generate_email(GenerateEmailOptions(channel="guerrillamail"))
47
+ print(f"邮箱: {info.email}")
48
+
49
+ # 获取邮件
50
+ result = get_emails(GetEmailsOptions(
51
+ channel=info.channel,
52
+ email=info.email,
53
+ token=info.token,
54
+ ))
55
+ if result.success:
56
+ print(f"收到 {len(result.emails)} 封邮件")
57
+ ```
58
+
59
+ ## 使用客户端类
60
+
61
+ ```python
62
+ from tempmail_sdk import TempEmailClient, GenerateEmailOptions
63
+
64
+ client = TempEmailClient()
65
+ info = client.generate(GenerateEmailOptions(channel="maildrop"))
66
+ result = client.get_emails()
67
+ ```
68
+
69
+ ## 日志
70
+
71
+ ```python
72
+ from tempmail_sdk import set_log_level, LOG_DEBUG
73
+
74
+ set_log_level(LOG_DEBUG) # 开启所有日志
75
+ ```
76
+
77
+ ## 重试配置
78
+
79
+ ```python
80
+ from tempmail_sdk import generate_email, GenerateEmailOptions, RetryConfig
81
+
82
+ info = generate_email(GenerateEmailOptions(
83
+ channel="temp-mail-io",
84
+ retry=RetryConfig(max_retries=3, initial_delay=2.0),
85
+ ))
86
+ ```
@@ -0,0 +1,25 @@
1
+ README.md
2
+ pyproject.toml
3
+ tempemail_sdk.egg-info/PKG-INFO
4
+ tempemail_sdk.egg-info/SOURCES.txt
5
+ tempemail_sdk.egg-info/dependency_links.txt
6
+ tempemail_sdk.egg-info/requires.txt
7
+ tempemail_sdk.egg-info/top_level.txt
8
+ tempmail_sdk/__init__.py
9
+ tempmail_sdk/client.py
10
+ tempmail_sdk/logger.py
11
+ tempmail_sdk/normalize.py
12
+ tempmail_sdk/retry.py
13
+ tempmail_sdk/types.py
14
+ tempmail_sdk/providers/__init__.py
15
+ tempmail_sdk/providers/awamail.py
16
+ tempmail_sdk/providers/chatgpt_org_uk.py
17
+ tempmail_sdk/providers/dropmail.py
18
+ tempmail_sdk/providers/guerrillamail.py
19
+ tempmail_sdk/providers/linshi_email.py
20
+ tempmail_sdk/providers/mail_tm.py
21
+ tempmail_sdk/providers/maildrop.py
22
+ tempmail_sdk/providers/temp_mail_io.py
23
+ tempmail_sdk/providers/tempmail.py
24
+ tempmail_sdk/providers/tempmail_la.py
25
+ tempmail_sdk/providers/tempmail_lol.py
@@ -0,0 +1,4 @@
1
+ requests>=2.28.0
2
+
3
+ [dev]
4
+ pytest>=7.0
@@ -0,0 +1 @@
1
+ tempmail_sdk
@@ -0,0 +1,53 @@
1
+ """
2
+ 临时邮箱 SDK (Python)
3
+ 支持 11 个邮箱服务提供商,所有渠道返回统一标准化格式
4
+ """
5
+
6
+ from .types import (
7
+ Channel,
8
+ EmailInfo,
9
+ Email,
10
+ EmailAttachment,
11
+ GetEmailsResult,
12
+ GenerateEmailOptions,
13
+ GetEmailsOptions,
14
+ RetryConfig,
15
+ ChannelInfo,
16
+ )
17
+ from .client import (
18
+ generate_email,
19
+ get_emails,
20
+ list_channels,
21
+ get_channel_info,
22
+ TempEmailClient,
23
+ )
24
+ from .logger import set_log_level, set_logger, get_logger, LOG_SILENT, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR
25
+ from .retry import with_retry
26
+ from .normalize import normalize_email
27
+
28
+ __all__ = [
29
+ "Channel",
30
+ "EmailInfo",
31
+ "Email",
32
+ "EmailAttachment",
33
+ "GetEmailsResult",
34
+ "GenerateEmailOptions",
35
+ "GetEmailsOptions",
36
+ "RetryConfig",
37
+ "ChannelInfo",
38
+ "generate_email",
39
+ "get_emails",
40
+ "list_channels",
41
+ "get_channel_info",
42
+ "TempEmailClient",
43
+ "set_log_level",
44
+ "set_logger",
45
+ "get_logger",
46
+ "LOG_SILENT",
47
+ "LOG_DEBUG",
48
+ "LOG_INFO",
49
+ "LOG_WARNING",
50
+ "LOG_ERROR",
51
+ "with_retry",
52
+ "normalize_email",
53
+ ]
@@ -0,0 +1,235 @@
1
+ """
2
+ SDK 主入口
3
+ 聚合所有渠道的逻辑,提供统一的 API
4
+ """
5
+
6
+ import random
7
+ from typing import Optional, List
8
+ from .types import (
9
+ EmailInfo, Email, GetEmailsResult,
10
+ GenerateEmailOptions, GetEmailsOptions,
11
+ ChannelInfo, RetryConfig,
12
+ )
13
+ from .retry import with_retry
14
+ from .logger import get_logger
15
+ from .providers import (
16
+ tempmail, linshi_email, tempmail_lol, chatgpt_org_uk,
17
+ tempmail_la, temp_mail_io, awamail, mail_tm,
18
+ dropmail, guerrillamail, maildrop,
19
+ )
20
+
21
+ # 所有支持的渠道列表
22
+ ALL_CHANNELS = [
23
+ "tempmail", "linshi-email", "tempmail-lol", "chatgpt-org-uk",
24
+ "tempmail-la", "temp-mail-io", "awamail", "mail-tm",
25
+ "dropmail", "guerrillamail", "maildrop",
26
+ ]
27
+
28
+ # 渠道信息映射表
29
+ CHANNEL_INFO_MAP = {
30
+ "tempmail": ChannelInfo(channel="tempmail", name="TempMail", website="tempmail.ing"),
31
+ "linshi-email": ChannelInfo(channel="linshi-email", name="临时邮箱", website="linshi-email.com"),
32
+ "tempmail-lol": ChannelInfo(channel="tempmail-lol", name="TempMail LOL", website="tempmail.lol"),
33
+ "chatgpt-org-uk": ChannelInfo(channel="chatgpt-org-uk", name="ChatGPT Mail", website="mail.chatgpt.org.uk"),
34
+ "tempmail-la": ChannelInfo(channel="tempmail-la", name="TempMail LA", website="tempmail.la"),
35
+ "temp-mail-io": ChannelInfo(channel="temp-mail-io", name="Temp Mail IO", website="temp-mail.io"),
36
+ "awamail": ChannelInfo(channel="awamail", name="AwaMail", website="awamail.com"),
37
+ "mail-tm": ChannelInfo(channel="mail-tm", name="Mail.tm", website="mail.tm"),
38
+ "dropmail": ChannelInfo(channel="dropmail", name="DropMail", website="dropmail.me"),
39
+ "guerrillamail": ChannelInfo(channel="guerrillamail", name="Guerrilla Mail", website="guerrillamail.com"),
40
+ "maildrop": ChannelInfo(channel="maildrop", name="Maildrop", website="maildrop.cc"),
41
+ }
42
+
43
+
44
+ def list_channels() -> List[ChannelInfo]:
45
+ """获取所有支持的渠道列表"""
46
+ return [CHANNEL_INFO_MAP[ch] for ch in ALL_CHANNELS]
47
+
48
+
49
+ def get_channel_info(channel: str) -> Optional[ChannelInfo]:
50
+ """获取指定渠道的详细信息"""
51
+ return CHANNEL_INFO_MAP.get(channel)
52
+
53
+
54
+ def generate_email(options: Optional[GenerateEmailOptions] = None) -> EmailInfo:
55
+ """
56
+ 创建临时邮箱
57
+
58
+ 错误处理策略:
59
+ - 网络错误、超时、HTTP 4xx/5xx → 自动重试(默认 2 次,指数退避)
60
+ - 重试耗尽后仍失败时抛出异常
61
+
62
+ 示例:
63
+ info = generate_email(GenerateEmailOptions(channel="guerrillamail"))
64
+ print(info.email)
65
+ """
66
+ if options is None:
67
+ options = GenerateEmailOptions()
68
+
69
+ channel = options.channel or random.choice(ALL_CHANNELS)
70
+ logger = get_logger()
71
+
72
+ logger.info(f"创建临时邮箱, 渠道: {channel}")
73
+
74
+ result = with_retry(
75
+ lambda: _generate_email_once(channel, options),
76
+ options.retry,
77
+ )
78
+
79
+ logger.info(f"邮箱创建成功: {result.email}")
80
+ return result
81
+
82
+
83
+ def _generate_email_once(channel: str, options: GenerateEmailOptions) -> EmailInfo:
84
+ """单次创建邮箱(不含重试逻辑)"""
85
+ if channel == "tempmail":
86
+ return tempmail.generate_email(options.duration)
87
+ elif channel == "linshi-email":
88
+ return linshi_email.generate_email()
89
+ elif channel == "tempmail-lol":
90
+ return tempmail_lol.generate_email(options.domain)
91
+ elif channel == "chatgpt-org-uk":
92
+ return chatgpt_org_uk.generate_email()
93
+ elif channel == "tempmail-la":
94
+ return tempmail_la.generate_email()
95
+ elif channel == "temp-mail-io":
96
+ return temp_mail_io.generate_email()
97
+ elif channel == "awamail":
98
+ return awamail.generate_email()
99
+ elif channel == "mail-tm":
100
+ return mail_tm.generate_email()
101
+ elif channel == "dropmail":
102
+ return dropmail.generate_email()
103
+ elif channel == "guerrillamail":
104
+ return guerrillamail.generate_email()
105
+ elif channel == "maildrop":
106
+ return maildrop.generate_email()
107
+ else:
108
+ raise ValueError(f"Unknown channel: {channel}")
109
+
110
+
111
+ def get_emails(options: GetEmailsOptions) -> GetEmailsResult:
112
+ """
113
+ 获取邮件列表
114
+
115
+ 错误处理策略:
116
+ - 网络错误、超时、HTTP 4xx/5xx → 自动重试(默认 2 次)
117
+ - 重试耗尽后返回 GetEmailsResult(success=False, emails=[])
118
+ - 参数校验错误直接抛出异常
119
+
120
+ 示例:
121
+ result = get_emails(GetEmailsOptions(
122
+ channel="guerrillamail",
123
+ email="xxx@guerrillamailblock.com",
124
+ token="sid_token_value",
125
+ ))
126
+ if result.success:
127
+ print(f"收到 {len(result.emails)} 封邮件")
128
+ """
129
+ channel = options.channel
130
+ email = options.email
131
+ token = options.token
132
+ logger = get_logger()
133
+
134
+ if not channel:
135
+ raise ValueError("channel is required")
136
+ if not email and channel != "tempmail-lol":
137
+ raise ValueError("email is required")
138
+
139
+ logger.debug(f"获取邮件, 渠道: {channel}, 邮箱: {email}")
140
+
141
+ try:
142
+ emails = with_retry(
143
+ lambda: _get_emails_once(channel, email, token),
144
+ options.retry,
145
+ )
146
+ if emails:
147
+ logger.info(f"获取到 {len(emails)} 封邮件, 渠道: {channel}")
148
+ else:
149
+ logger.debug(f"暂无邮件, 渠道: {channel}")
150
+
151
+ return GetEmailsResult(channel=channel, email=email, emails=emails, success=True)
152
+ except Exception as e:
153
+ logger.error(f"获取邮件失败, 渠道: {channel}, 错误: {e}")
154
+ return GetEmailsResult(channel=channel, email=email, emails=[], success=False)
155
+
156
+
157
+ def _get_emails_once(channel: str, email: str, token: Optional[str]) -> List[Email]:
158
+ """单次获取邮件(不含重试逻辑)"""
159
+ if channel == "tempmail":
160
+ return tempmail.get_emails(email)
161
+ elif channel == "linshi-email":
162
+ return linshi_email.get_emails(email)
163
+ elif channel == "tempmail-lol":
164
+ if not token:
165
+ raise ValueError("token is required for tempmail-lol channel")
166
+ return tempmail_lol.get_emails(token, email)
167
+ elif channel == "chatgpt-org-uk":
168
+ return chatgpt_org_uk.get_emails(email)
169
+ elif channel == "tempmail-la":
170
+ return tempmail_la.get_emails(email)
171
+ elif channel == "temp-mail-io":
172
+ return temp_mail_io.get_emails(email)
173
+ elif channel == "awamail":
174
+ if not token:
175
+ raise ValueError("token is required for awamail channel")
176
+ return awamail.get_emails(token, email)
177
+ elif channel == "mail-tm":
178
+ if not token:
179
+ raise ValueError("token is required for mail-tm channel")
180
+ return mail_tm.get_emails(token, email)
181
+ elif channel == "dropmail":
182
+ if not token:
183
+ raise ValueError("token is required for dropmail channel")
184
+ return dropmail.get_emails(token, email)
185
+ elif channel == "guerrillamail":
186
+ if not token:
187
+ raise ValueError("token is required for guerrillamail channel")
188
+ return guerrillamail.get_emails(token, email)
189
+ elif channel == "maildrop":
190
+ if not token:
191
+ raise ValueError("token is required for maildrop channel")
192
+ return maildrop.get_emails(token, email)
193
+ else:
194
+ raise ValueError(f"Unknown channel: {channel}")
195
+
196
+
197
+ class TempEmailClient:
198
+ """
199
+ 临时邮箱客户端
200
+ 封装了邮箱创建和邮件获取的完整流程,自动管理邮箱信息和认证令牌
201
+
202
+ 示例:
203
+ client = TempEmailClient()
204
+ info = client.generate(GenerateEmailOptions(channel="maildrop"))
205
+ result = client.get_emails()
206
+ if result.success:
207
+ print(f"收到 {len(result.emails)} 封邮件")
208
+ """
209
+
210
+ def __init__(self):
211
+ self._email_info: Optional[EmailInfo] = None
212
+
213
+ def generate(self, options: Optional[GenerateEmailOptions] = None) -> EmailInfo:
214
+ """创建临时邮箱并缓存邮箱信息"""
215
+ self._email_info = generate_email(options)
216
+ return self._email_info
217
+
218
+ def get_emails(self, options: Optional[GetEmailsOptions] = None) -> GetEmailsResult:
219
+ """获取当前邮箱的邮件列表,必须先调用 generate()"""
220
+ if self._email_info is None:
221
+ raise RuntimeError("No email generated. Call generate() first")
222
+
223
+ if options is None:
224
+ options = GetEmailsOptions(
225
+ channel=self._email_info.channel,
226
+ email=self._email_info.email,
227
+ token=self._email_info.token,
228
+ )
229
+
230
+ return get_emails(options)
231
+
232
+ @property
233
+ def email_info(self) -> Optional[EmailInfo]:
234
+ """获取当前缓存的邮箱信息"""
235
+ return self._email_info
@@ -0,0 +1,54 @@
1
+ """
2
+ SDK 日志模块
3
+ 基于 Python 标准库 logging 实现分级日志
4
+ 默认静默不输出,用户可通过 set_log_level 启用
5
+ """
6
+
7
+ import logging
8
+
9
+ LOG_SILENT = 100 # 关闭所有日志
10
+ LOG_ERROR = logging.ERROR
11
+ LOG_WARNING = logging.WARNING
12
+ LOG_INFO = logging.INFO
13
+ LOG_DEBUG = logging.DEBUG
14
+
15
+ # 创建 SDK 专用 logger
16
+ _logger = logging.getLogger("tempmail-sdk")
17
+ _logger.setLevel(LOG_SILENT)
18
+
19
+ # 默认不添加 handler,避免重复输出
20
+ _handler = logging.StreamHandler()
21
+ _handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
22
+ _logger.addHandler(_handler)
23
+ _logger.propagate = False
24
+
25
+
26
+ def set_log_level(level: int) -> None:
27
+ """
28
+ 设置日志级别
29
+ 默认 LOG_SILENT(不输出任何日志)
30
+
31
+ 示例:
32
+ from tempmail_sdk import set_log_level, LOG_DEBUG
33
+ set_log_level(LOG_DEBUG) # 开启所有日志
34
+ """
35
+ _logger.setLevel(level)
36
+
37
+
38
+ def set_logger(logger: logging.Logger) -> None:
39
+ """
40
+ 设置自定义 logger 实例
41
+ 替换默认的 stderr 输出
42
+
43
+ 示例:
44
+ import logging
45
+ my_logger = logging.getLogger("my_app")
46
+ set_logger(my_logger)
47
+ """
48
+ global _logger
49
+ _logger = logger
50
+
51
+
52
+ def get_logger() -> logging.Logger:
53
+ """获取当前 SDK 使用的 logger 实例"""
54
+ return _logger