-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtempmail
More file actions
179 lines (164 loc) · 4.49 KB
/
Copy pathtempmail
File metadata and controls
179 lines (164 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# Configuration variables
API_BASE_URL="https://tempmail-so.p.rapidapi.com"
CONFIG_FILE="$HOME/.tempmail_config"
# Check configuration file
load_config() {
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
echo "Please configure API key and token first"
echo "Usage: ./tempmail config <rapidapi-key> <auth-token>"
exit 1
fi
}
# Function to make API requests
call_api() {
local method=$1
local endpoint=$2
local data=$3
if [ -n "$data" ]; then
curl -s -X "$method" \
"$API_BASE_URL$endpoint" \
-H "x-rapidapi-key: $RAPID_API_KEY" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "$data"
else
curl -s -X "$method" \
"$API_BASE_URL$endpoint" \
-H "x-rapidapi-key: $RAPID_API_KEY" \
-H "Authorization: Bearer $AUTH_TOKEN"
fi
}
# Save configuration
save_config() {
echo "RAPID_API_KEY=$1" > "$CONFIG_FILE"
echo "AUTH_TOKEN=$2" >> "$CONFIG_FILE"
chmod 600 "$CONFIG_FILE"
echo "Configuration saved"
}
# Display available domains
list_domains() {
echo "Getting available domains..."
call_api "GET" "/domains"
}
# Create new inbox
create_inbox() {
local name=$1
local domain=$2
local lifespan=${3:-0}
echo "Creating new inbox..."
call_api "POST" "/inboxes" "name=$name&domain=$domain&lifespan=$lifespan"
}
# List all inboxes
list_inboxes() {
echo "Getting all inboxes..."
call_api "GET" "/inboxes"
}
# Delete inbox
delete_inbox() {
local inbox_id=$1
echo "Deleting inbox $inbox_id..."
call_api "DELETE" "/inboxes/$inbox_id"
}
# List emails
list_mails() {
local inbox_id=$1
echo "Getting all emails from inbox $inbox_id..."
call_api "GET" "/inboxes/$inbox_id/mails"
}
# Read email content
read_mail() {
local inbox_id=$1
local mail_id=$2
echo "Reading email content..."
call_api "GET" "/inboxes/$inbox_id/mails/$mail_id"
}
# Delete email
delete_mail() {
local inbox_id=$1
local mail_id=$2
echo "Deleting email..."
call_api "DELETE" "/inboxes/$inbox_id/mails/$mail_id"
}
# Show usage help
show_help() {
echo "Temporary Email Service Command Line Tool"
echo
echo "Required Credentials:"
echo " - Auth Token: Get from https://tempmail.so"
echo " - RapidAPI Key: Get from https://rapidapi.com/"
echo
echo "Usage:"
echo " ./tempmail config <rapidapi-key> <auth-token> # Configure API key"
echo " ./tempmail domains # Show available domains"
echo " ./tempmail create <name> <domain> [lifespan] # Create new inbox"
echo " ./tempmail list # List all inboxes"
echo " ./tempmail delete-inbox <inbox-id> # Delete inbox"
echo " ./tempmail list-mails <inbox-id> # List emails in inbox"
echo " ./tempmail read-mail <inbox-id> <mail-id> # Read email content"
echo " ./tempmail delete-mail <inbox-id> <mail-id> # Delete email"
echo " ./tempmail help # Show this help message"
}
# Main program
case $1 in
"config")
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Please provide RapidAPI key and auth token"
exit 1
fi
save_config "$2" "$3"
;;
"domains")
load_config
list_domains
;;
"create")
load_config
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Please provide inbox name and domain"
exit 1
fi
create_inbox "$2" "$3" "$4"
;;
"list")
load_config
list_inboxes
;;
"delete-inbox")
load_config
if [ -z "$2" ]; then
echo "Please provide inbox ID"
exit 1
fi
delete_inbox "$2"
;;
"list-mails")
load_config
if [ -z "$2" ]; then
echo "Please provide inbox ID"
exit 1
fi
list_mails "$2"
;;
"read-mail")
load_config
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Please provide inbox ID and mail ID"
exit 1
fi
read_mail "$2" "$3"
;;
"delete-mail")
load_config
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Please provide inbox ID and mail ID"
exit 1
fi
delete_mail "$2" "$3"
;;
"help"|*)
show_help
;;
esac