-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdep.go
82 lines (64 loc) · 1.81 KB
/
dep.go
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
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"github.com/gookit/color"
)
func getAvailableDomains() ([]string, error) {
var availableDomains []string
response, err := http.Get("https://www.1secmail.com/api/v1/?action=getDomainList")
if err != nil {
return availableDomains, errors.New("error in getting domain list from server")
}
responseData, err := io.ReadAll(response.Body)
if err != nil {
return availableDomains, errors.New("error in parsing the response")
}
_ = json.Unmarshal(responseData, &availableDomains)
return availableDomains, nil
}
func createEmail(name string, domain string) (string, error) {
info := fmt.Sprintf("https://www.1secmail.com/?login=%v&domain=%v", name, domain)
resp, err := http.Get(info)
if err != nil {
return "", err
}
if resp.StatusCode != 200 {
return "", errors.New("email was not created")
}
email := name + "@" + domain
return email, nil
}
func checkMail(name string, domainOnly string) int {
s := fmt.Sprintf("https://www.1secmail.com/api/v1/?action=getMessages&login=%v&domain=%v", name, domainOnly)
resp, _ := http.Get(s)
body, _ := io.ReadAll(resp.Body)
err := json.Unmarshal([]byte(body), &mailsResponse)
if err != nil {
fmt.Println(err)
}
resp.Body.Close()
totalEmails := len(mailsResponse)
switch totalEmails {
case 0:
color.Yellow.Println("Mailbox is empty")
case 1:
color.Cyan.Println("You received 1 mail in your mailbox")
default:
color.Green.Println("You received,", totalEmails, "mail in your mailbox")
}
return totalEmails
}
func deleteMail(name string, domainOnly string) error {
delUrl := "https://www.1secmail.com/mailbox"
data := url.Values{}
data.Set("action", "deleteMailbox")
data.Set("login", name)
data.Set("domain", domainOnly)
_, err := http.PostForm(delUrl, data)
return err
}