Parcourir la source

Merge pull request #6 from anthonybaldwin/master

Add custom email
Siddharth Dushantha il y a 5 ans
Parent
commit
cad9f667b4
2 fichiers modifiés avec 23 ajouts et 5 suppressions
  1. 17 2
      README.md
  2. 6 3
      tmpmail

+ 17 - 2
README.md

@@ -7,6 +7,8 @@
 and receive emails to the temporary email address. It uses 1secmail's [API](https://www.1secmail.com/api/)
 to receive emails.
 
+By default, emails will be generated by random unless the `--generate` argument is followed by the desired username.
+
 By default `w3m` is used to render the HTML emails on the terminal.
 But if you prefer another text based web browser or would rather view the email in a GUI web browser such as Firefox, simply
 use the `--browser` argument followed by the command needed to launch the web browser of your choice.
@@ -41,18 +43,31 @@ $ yay -S tmpmail-git
 
 ## Usage
 ```console
+$ tmpmail --help
 usage: tmpmail [-h] [--generate] [--text] [--browser BROWSER] [--recent] ID
 
 optional arguments:
 -h, --help           Show this help message
     --version        Print version
--g, --generate       Generate a new email address
+-g, --generate       Generate a new email address. You may aslo pass a custom username along with this flag
 -r, --recent         View the most recent email
 -t, --text           View the email as raw text, where all the HTML tags are removed
 -b, --browser        Change the browser that is used to render the HTML of the email (default: w3m)
 ```
 
 ### Examples
+Create random email
+```console
+$ tmpmail --generate
+xoithrjagpx@1secmail.net
+```
+
+Create custom email
+```console
+$ tmpmail --generate mycustomemail
+mycustomemail@1secmail.com
+```
+
 View the inbox
 ```console
 $ tmpmail
@@ -81,5 +96,5 @@ Subject: Test Email
 Hello World
 ```
 
-## Credits 
+## Credits
 This script is heavily inspired by Mitch Weaver's [`1secmail`](https://github.com/mitchweaver/bin/blob/master/application/1secmail) script

+ 6 - 3
tmpmail

@@ -8,7 +8,7 @@
 export LC_ALL=C
 export LC_CTYPE=C
 
-VERSION=1.0.4
+VERSION=1.0.5
 
 # By default 'tmpmail' uses 'w3m' as it's web browser to render
 # the HTML of the email
@@ -43,7 +43,7 @@ usage: tmpmail [-h] [--generate] [--browser BROWSER] [--recent] ID
 optional arguments:
 -h, --help           Show this help message
     --version        Print version
--g, --generate       Generate a new email address
+-g, --generate       Generate a new email address. You may aslo pass a custom username along with this flag
 -r, --recent         View the most recent email
 -t, --text           View the email as raw text, where all the HTML tags are removed
 -b, --browser        Change the browser that is used to render the HTML of the email (default: w3m)
@@ -71,6 +71,7 @@ generate_email_address() {
     # We need this variable so we can know whether or not we need to show the user
     # what the email was. <-- More about this can be found further down in this function.
     EXTERNALLY=${1:-false}
+    CUSTOM=${2:-false}
 
     # Generate a random email address.
     # This function is called whenever the user wants to generate a new email
@@ -84,6 +85,8 @@ generate_email_address() {
     # the first 10 characters, which will be the username of the email address
     USERNAME=$(head /dev/urandom | tr -dc a-z | cut -c1-11)
 
+    [ "$CUSTOM" != false ] && USERNAME=$CUSTOM
+
     # This is an array of the valid TLDS which 1secmail provides.
     TLDS=(com net org)
 
@@ -271,7 +274,7 @@ main() {
     while [[ "$1" ]]; do
         case "$1" in
             --help | -h) usage && exit ;;
-            --generate | -g) generate_email_address true && exit ;;
+            --generate | -g) generate_email_address true "$2" && exit ;;
             --browser | -b) BROWSER="$2" ;;
             --text | -t) RAW_TEXT=true ;;
             --version) echo "$VERSION" && exit ;;