Skip to content

Commit 9222835

Browse files
committed
✨ Add option to set custom domain.
Signed-off-by: Ashish Saini <sainiashish08@gmail.com>
1 parent 214e7dd commit 9222835

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Create and view temporary mailbox using 1secmail [API](https://www.1secmail.com/
1111
* _appdirs_
1212

1313
## Installation
14-
3. Install using `pip install git+https://github.com/meashishsaini/tmpmail-python`
14+
1. Install using `pip install git+https://github.com/meashishsaini/tmpmail-python`
1515

1616
## Usage
1717
```
18-
tmpmail [-h] [-g [USERNAME]] [-r] [-t] [-b [BROWSER]] [id]
18+
tmpmail [-h] [-g [USERNAME]] [-r] [-t] [-b [BROWSER]]
19+
[-d {1secmail.com,1secmail.org,1secmail.net,wwjmp.com,esiix.com}]
20+
[id]
1921
2022
positional arguments:
2123
id id of the email received
@@ -28,7 +30,9 @@ optional arguments:
2830
-t, --text view email as pure text.
2931
-b [BROWSER], --browser [BROWSER]
3032
open email in given browser.
33+
-d {1secmail.com,1secmail.org,1secmail.net,wwjmp.com,esiix.com}, --domain {1secmail.com,1secmail.org,1secmail.net,wwjmp.com,esiix.com}
34+
set a custom domain supported by 1secmail.
3135
```
3236

3337
## Credits
34-
The python version inspired by Siddharth Dushantha's [tmpmail](https://github.com/sdushantha/tmpmail) script.
38+
The python version is inspired by Siddharth Dushantha's [tmpmail](https://github.com/sdushantha/tmpmail) script.

tmpmail/api/one_sec_mail.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,20 @@ def dict_to_obj(cls, our_dict: dict):
4949
class OneSecMail(APIBase):
5050
def __init__(self, username, domain="1secmail.org"):
5151
super().__init__()
52+
if not self.is_valid_domain(domain):
53+
raise Exception("Illegal domain.")
5254
self.domain = domain
5355
self.username = username
5456
self.url = f"https://www.1secmail.com/api/v1/?domain={self.domain}&login={self.username}"
5557

58+
@classmethod
59+
def is_valid_domain(cls, domain: str):
60+
return domain in cls.valid_domains()
61+
62+
@classmethod
63+
def valid_domains(cls):
64+
return ["1secmail.com", "1secmail.org", "1secmail.net", "wwjmp.com", "esiix.com"]
65+
5666
def check_mailbox(self) -> list:
5767
action = "getMessages"
5868
check_url = f"{self.url}&action={action}"

tmpmail/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,21 @@ def parse():
7474
argparser.add_argument("-r", "--recent", help="view most recent email.", action="store_true")
7575
argparser.add_argument("-t", "--text", help="view email as pure text.", action="store_true")
7676
argparser.add_argument("-b", "--browser", help="open email in given browser.", type=str, nargs="?", default=SUPPRESS)
77+
argparser.add_argument("-d", "--domain", help="set a custom domain supported by 1secmail.", type=str, default=SUPPRESS, choices=OneSecMail.valid_domains())
7778
args = argparser.parse_args()
7879

7980
config = load_config()
8081

8182
if "username" in args:
8283
config["username"] = args.username if args.username else random_username()
8384
create_config(username=config.get("username"), domain=config.get("domain"))
85+
86+
if "domain" in args:
87+
if OneSecMail.is_valid_domain(args.domain):
88+
config["domain"] = args.domain
89+
create_config(username=config.get("username"), domain=config.get("domain"))
90+
else:
91+
print("Illegal domain name provided.")
8492

8593
one_sec_mail = OneSecMail(**config)
8694

0 commit comments

Comments
 (0)