فهرست منبع

allow custom email address instead of username

In #6 we implemented a feature where the user could provide a custom
username. The reason for adding this feature was because of
@zanona's very good reason for adding this feature:

> Perhaps we could pass an argument to the generation function in
> order to access an inbox for an email we created in the past?
> Let's say, a login for a forum

But #6 had a minor issue which went unoticed. It only allowed you
provide a username and not an email address. The issue with this is that
it does not satisfy @zanona's need, which was to access an inbox for an
old email address.
Why was that not possible? Because when you gave the username, the TLD
would still be random.

This scenario explains the issue:
Lets say bob@1secmail.com was randomly generate, and I used this
email to sign up for a forum and receive their confirmation email.
I then randomly generated a new email which resulted in this email
address: alice@1secmail.org
A few days later, I want to access the inbox of bob@1secmail.com, so I
run 'tmpmail --generate bob' which might give me this email:
bob@1secmail.net
Notice how it ends with .net and not .com like the email I wanted to
access.

So this commit intends to fix this minor bug/issue.
Siddharth Dushantha 5 سال پیش
والد
کامیت
ce2c3eaed9
1فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 13 2
      tmpmail

+ 13 - 2
tmpmail

@@ -8,7 +8,7 @@
 export LC_ALL=C
 export LC_CTYPE=C
 
-VERSION=1.0.5
+VERSION=1.0.6
 
 # By default 'tmpmail' uses 'w3m' as it's web browser to render
 # the HTML of the email
@@ -73,6 +73,10 @@ generate_email_address() {
     EXTERNALLY=${1:-false}
     CUSTOM=${2:-false}
 
+    # This variable lets generate_email_address know if the user has provided a custom
+    # email address which they want to use
+    CUSTOM=${2:-false}
+
     # Generate a random email address.
     # This function is called whenever the user wants to generate a new email
     # address by running 'tmpmail --generate' or when the user runs 'tmpmail'
@@ -93,9 +97,16 @@ generate_email_address() {
     # Randomly pick one of the TLDS mentiond above.
     TLD=${TLDS[$RANDOM % ${#TLDS[@]}]}
 
+    EMAIL_ADDRESS="$USERNAME@1secmail.$TLD"
+
+    # If the user provided a custom email address which matches
+    # [a-zA-Z0-9_\-\.]+@1secmail\.(com|net|org)
+    # then use that email address
+    [ "$CUSTOM" != false ] && EMAIL_ADDRESS=$CUSTOM
+
     # Save the generated email address to the $TMPMAIL_EMAIL_ADDRESS file
     # so that it can be whenever 'tmpmail' is run
-    echo "$USERNAME@1secmail.$TLD" >"$TMPMAIL_EMAIL_ADDRESS"
+    echo $EMAIL_ADDRESS >"$TMPMAIL_EMAIL_ADDRESS"
 
     # If this function was called because the user wanted to generate a new
     # email address, show them the email address