Skip to content

Commit 9ed0bf5

Browse files
Create tempmail.sh
1 parent fb1b597 commit 9ed0bf5

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tempmail.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
3+
# made with NANO, the right way
4+
5+
# depends on bash, curl, jq, and your support :)
6+
7+
# support: https://github.com/tempmail-lol/tempmail-cli
8+
9+
BASE_URL="https://api.tempmail.lol"
10+
11+
# temporarily disable ifs
12+
IFS_OLD=$IFS
13+
IFS=
14+
15+
HELP_STR="TempMail CLI
16+
Generate temporary email addresses from the command line!
17+
18+
For help, visit https://github.com/tempmail-lol/tempmail-cli
19+
20+
ARGUMENTS:
21+
--help Show this help menu.
22+
--rush -r Use Rush Mode.
23+
--verbose -v Enable verbose mode.
24+
--lynx -l Render email HTML (requires lynx).
25+
26+
Copyright (C) Alexander Epolite
27+
"
28+
29+
function debug() {
30+
[ "$VERBOSE" == "true" ] && echo "[VERBOSITY] $1"
31+
}
32+
33+
RUSH=""
34+
VERBOSE=false
35+
LYNX=false
36+
37+
# command line args
38+
while [ 1=1 ]
39+
do
40+
case $1 in
41+
--help) echo $HELP_STR && exit 0 ;;
42+
--rush | -r) RUSH="/rush" ; shift ;;
43+
--verbose | -v) VERBOSE=true ; shift ;;
44+
--lynx | -l) LYNX=true ; shift ;;
45+
*) break ;;
46+
esac
47+
done
48+
49+
# reset ifs
50+
IFS=$IFS_OLD
51+
52+
debug "Rush Mode: $RUSH"
53+
54+
GENERATION_TEMP="$(curl -s $BASE_URL/generate$RUSH)"
55+
56+
debug "Generation data: $GENERATION_TEMP"
57+
58+
ADDRESS=$(echo $GENERATION_TEMP | jq -r ".address")
59+
TOKEN=$(echo $GENERATION_TEMP | jq -r ".token")
60+
61+
echo "Your temporary email is $ADDRESS"
62+
63+
# since users will be copying, prevent ctrl c from exiting
64+
65+
term() {
66+
echo "To copy, hover over the text, right click, and press copy."
67+
echo "To exit, press 'q'. Your inbox will be lost on exit."
68+
}
69+
70+
debug "Token: $TOKEN"
71+
72+
trap term INT
73+
74+
# if lynx is enabled, make sure that it exists
75+
if [ "$LYNX" == "true" ]
76+
then
77+
if ! command -v lynx &> /dev/null
78+
then
79+
echo "Could not find lynx, it has been disabled."
80+
LYNX=false
81+
fi
82+
fi
83+
84+
while [ 1=1 ]
85+
do
86+
# break on the q character
87+
read -N 1 -t 5 -r -s && [[ $REPLY == 'q' ]] && exit 0
88+
89+
EC=$?
90+
91+
# if the result is not a timeout, continue (so the api
92+
# isn't spammed if someone holds down a certain character)
93+
[ $EC -ne 142 ] && continue
94+
95+
CHECK=$(curl "$BASE_URL/auth/$TOKEN" -s)
96+
debug "HTTP result: $CHECK"
97+
PARSE_A=$(echo $CHECK | jq -r ".email")
98+
99+
[ "$PARSE_A" == "[]" ] && continue;
100+
101+
FROM=$(echo $CHECK | jq -r ".email[].from")
102+
BODY=$(echo $CHECK | jq -r ".email[].body")
103+
HTML=$(echo $CHECK | jq -r ".email[].html")
104+
IP=$(echo $CHECK | jq -r ".email[].ip")
105+
106+
debug "HTML: $HTML"
107+
108+
if [ "$LYNX" == "true" ]
109+
then
110+
if [ "$HTML" != "null" ]
111+
then
112+
echo $HTML | lynx -stdin
113+
continue
114+
fi
115+
fi
116+
117+
echo "You got a new email!"
118+
119+
IFS=
120+
121+
echo "
122+
From: $FROM
123+
To: $ADDRESS
124+
Originating IP: $IP
125+
Body: $BODY"
126+
127+
IFS=$IFS_OLD
128+
done

0 commit comments

Comments
 (0)