Skip to content

Commit

Permalink
Added basic baemail integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jun 3, 2020
1 parent c59b236 commit bc8d7ce
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ paymail

**Install using a [compiled binary](https://github.com/mrz1836/paymail-inspector/releases)** on Linux, Mac or Windows _(Mac example)_
```shell script
curl -LkSs https://github.com/mrz1836/paymail-inspector/releases/download/v0.1.11/paymail-inspector_macOS_64-bit.tar.gz -o app.tar.gz
curl -LkSs https://github.com/mrz1836/paymail-inspector/releases/download/v0.1.12/paymail-inspector_macOS_64-bit.tar.gz -o app.tar.gz
tar -zxf app.tar.gz && cd ./app/
./paymail
```
Expand Down Expand Up @@ -198,10 +198,10 @@ Additional paymail information can also be found via [MoneyButton's documentatio
<summary><strong><code>Integrated Services</code></strong></summary>
<br/>

- Unwriter's [bitpic](https://bitpic.network/)
- Deggen's [Roundesk](https://roundesk.co/)
- RelayX's [Dime.ly](https://dimely.io)
- [2paymail](https://2paymail.com/)
- Unwriter's [bitpic](https://tncpw.co/e4d6ce84)
- Deggen's [Roundesk](https://tncpw.co/2d8d2e22) & [Baemail](https://tncpw.co/2c90c26b)
- RelayX's [Dime.ly](https://tncpw.co/46a4d32d)
- [2paymail](https://tncpw.co/c82bd419)
</details>

<details>
Expand Down
70 changes: 70 additions & 0 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/mrz1836/paymail-inspector/chalker"
"github.com/mrz1836/paymail-inspector/database"
twopaymail "github.com/mrz1836/paymail-inspector/integrations/2paymail"
"github.com/mrz1836/paymail-inspector/integrations/baemail"
"github.com/mrz1836/paymail-inspector/integrations/bitpic"
"github.com/mrz1836/paymail-inspector/integrations/roundesk"
"github.com/mrz1836/paymail-inspector/paymail"
Expand Down Expand Up @@ -499,6 +500,62 @@ func getRoundeskProfile(alias, domain string, allowCache bool) (profile *roundes
return
}

// getBaemail will check to see if a Baemail account exists for a given paymail
func getBaemail(alias, domain string, allowCache bool) (response *baemail.Response, err error) {

// Start the request
displayHeader(chalker.DEFAULT, fmt.Sprintf("Checking %s for a Baemail account...", chalk.Cyan.Color(alias+"@"+domain)))

// Cache key
keyName := "app-baemail-" + alias + "@" + domain

// Do we have caching and db?
if !disableCache && databaseEnabled && allowCache {
var jsonStr string
if jsonStr, err = database.Get(keyName); err != nil {
return
}
if len(jsonStr) > 0 {
if err = json.Unmarshal([]byte(jsonStr), &response); err != nil {
return
}
chalker.Log(chalker.SUCCESS, "Baemail account was found (from cache)")
return
}
}

// Does this paymail have a Baemail account
if response, err = baemail.HasProfile(alias, domain, !skipTracing); err != nil {
return
}

// Display the tracing results
if !skipTracing {
displayTracingResults(response.Tracing, response.StatusCode)
}

// Success or failure
if response != nil && len(response.ComposeURL) > 0 {
chalker.Log(chalker.SUCCESS, "Baemail account was found")

// Store in db?
if databaseEnabled {
var jsonStr []byte
if jsonStr, err = json.Marshal(response); err != nil {
return
}
if err = database.Set(keyName, string(jsonStr), 1*time.Hour); err != nil {
return
}
}

} else {
chalker.Log(chalker.DEFAULT, "Baemail account was not found")
}

return
}

// get2paymail will get a 2paymail account if it exists
func get2paymail(alias, domain string, allowCache bool) (profile *twopaymail.Response, err error) {

Expand Down Expand Up @@ -656,6 +713,7 @@ func (p *PaymailDetails) GetPublicInfo(capabilities *paymail.CapabilitiesRespons

// Attempt to get a bitpic (if enabled)
if !skipBitpic && p.PKI != nil && len(p.PKI.Handle) > 0 {
// todo: make this one request to get all bitpics
if p.Bitpic, err = getBitPic(p.Handle, p.Provider.Domain, true); err != nil {
err = fmt.Errorf("checking for bitpic failed: %s", err.Error())
}
Expand All @@ -671,6 +729,13 @@ func (p *PaymailDetails) GetPublicInfo(capabilities *paymail.CapabilitiesRespons
}
}

// Attempt to check for a Baemail profile (if enabled)
if !skipBaemail && p.PKI != nil && len(p.PKI.Handle) > 0 {
if p.Baemail, err = getBaemail(p.Handle, p.Provider.Domain, true); err != nil {
err = fmt.Errorf("checking for baemail account failed: %s", err.Error())
}
}

// Attempt to get a Roundesk profile (if enabled)
if !skipRoundesk && p.PKI != nil && len(p.PKI.Handle) > 0 {
if p.Roundesk, err = getRoundeskProfile(p.Handle, p.Provider.Domain, true); err != nil {
Expand Down Expand Up @@ -721,6 +786,11 @@ func (p *PaymailDetails) Display() {
}
}

// Display the baemail compose url if found
if p.Baemail != nil && len(p.Baemail.ComposeURL) > 0 {
chalker.Log(chalker.DEFAULT, fmt.Sprintf("Baemail : %s", chalk.Cyan.Color(p.Baemail.ComposeURL)))
}

// Display dime.ly if found
if len(p.Dimely) > 0 {
chalker.Log(chalker.DEFAULT, fmt.Sprintf("Dime.ly : %s", chalk.Cyan.Color(p.Dimely)))
Expand Down
5 changes: 4 additions & 1 deletion cmd/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package cmd
import (
"github.com/mrz1836/go-sanitize"
twopaymail "github.com/mrz1836/paymail-inspector/integrations/2paymail"
"github.com/mrz1836/paymail-inspector/integrations/baemail"
"github.com/mrz1836/paymail-inspector/integrations/bitpic"
"github.com/mrz1836/paymail-inspector/integrations/roundesk"
"github.com/mrz1836/paymail-inspector/paymail"
)

// Version is set manually (also make:build overwrites this value from Github's latest tag)
var Version = "v0.1.11"
var Version = "v0.1.12"

// Default flag values for various commands
var (
Expand All @@ -30,6 +31,7 @@ var (
serviceName string // cmd: validate
signature string // cmd: resolve
skip2paymail bool // cmd: resolve
skipBaemail bool // cmd: resolve
skipBitpic bool // cmd: resolve
skipBrfcValidation bool // cmd: brfc
skipDnsCheck bool // cmd: validate
Expand Down Expand Up @@ -93,6 +95,7 @@ func getProvider(domain string) *Provider {

// PaymailDetails is all the info about one paymail address
type PaymailDetails struct {
Baemail *baemail.Response `json:"baemail"`
Bitpic string `json:"bitpic"`
Bitpics *bitpic.SearchResponse `json:"bitpics"`
Dimely string `json:"dimely"`
Expand Down
3 changes: 3 additions & 0 deletions cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,7 @@ func init() {

// Skip getting Roundesk profile
resolveCmd.Flags().BoolVar(&skipRoundesk, "skip-roundesk", false, "Skip trying to get an associated Roundesk profile")

// Skip getting Baemail account
resolveCmd.Flags().BoolVar(&skipRoundesk, "skip-baemail", false, "Skip trying to get an associated Baemail account")
}
2 changes: 1 addition & 1 deletion docs/commands/paymail.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __________ .__.__ .___
| ___/\__ \< | |/ \\__ \ | | | | |/ \ / ___/\____ \_/ __ \_/ ___\ __\/ _ \_ __ \
| | / __ \\___ | Y Y \/ __ \| | |__ | | | \\___ \ | |_> > ___/\ \___| | ( <_> ) | \/
|____| (____ / ____|__|_| (____ /__|____/ |___|___| /____ >| __/ \___ >\___ >__| \____/|__|
\/\/ \/ \/ \/ \/ |__| \/ \/ v0.1.11
\/\/ \/ \/ \/ \/ |__| \/ \/ v0.1.12
```
Author: MrZ © 2020 github.com/mrz1836/paymail-inspector

Expand Down
1 change: 1 addition & 0 deletions docs/commands/paymail_resolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ paymail r mrz@moneybutton.com
--sender-name string The sender's name
-s, --signature string The signature of the entire request
--skip-2paymail Skip trying to get an associated 2paymail
--skip-baemail Skip trying to get an associated Baemail account
--skip-bitpic Skip trying to get an associated Bitpic
--skip-pki Skip the pki request
--skip-public-profile Skip the public profile request
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/paymail_whois.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ __ _ _| |__ ____ |__| ______
```


Search 8 public paymail providers for a handle.
Search 9 public paymail providers for a handle.

```
paymail whois [flags]
Expand Down
82 changes: 82 additions & 0 deletions integrations/baemail/baemail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Package baemail interfaces with Deggen's Baemail
Read more at: https://baemail.me/
*/
package baemail

import (
"fmt"
"net/http"
"time"

"github.com/go-resty/resty/v2"
)

// Defaults for baemail package
const (
defaultGetTimeout = 15 // In seconds
defaultUserAgent = "go:baemail" // Default user agent
baemailURL = "https://baemail.me" // Network to use
)

// Override the package defaults
var (
Network = baemailURL // override the default network
UserAgent = defaultUserAgent // override the default user agent
)

// Response is the standard fields returned on all responses
type Response struct {
ComposeURL string `json:"compose_url"` // Compose email url
Found bool `json:"found"` // Flag if the profile was found
StatusCode int `json:"status_code"` // Status code returned on the request
Tracing resty.TraceInfo `json:"tracing"` // Trace information if enabled on the request
}

// HasProfile will check if a profile exists for the given paymail address
// Specs: (no docs)
func HasProfile(alias, domain string, tracing bool) (response *Response, err error) {

// Set the url for the request
reqURL := fmt.Sprintf("%s/api/exists/%s@%s", Network, alias, domain)

// Create a Client and start the request
client := resty.New().SetTimeout(defaultGetTimeout * time.Second)
var resp *resty.Response
req := client.R().SetHeader("User-Agent", UserAgent)
if tracing {
req.EnableTrace()
}
if resp, err = req.Get(reqURL); err != nil {
return
}

// Start the response
response = new(Response)

// Tracing enabled?
if tracing {
response.Tracing = resp.Request.TraceInfo()
}

// Check for a successful status code
response.StatusCode = resp.StatusCode()
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusNotModified {
err = fmt.Errorf("bad response from baemail provider: %d", response.StatusCode)
return
}

// Test the response
response.Found = string(resp.Body()) == "1"
if response.Found {
response.ComposeURL = Compose(alias, domain)
}

return
}

// Compose will return a url for composing a baemail
// Specs: https://baemail.me/compose?to=user%40domain
func Compose(alias, domain string) (url string) {
return fmt.Sprintf("%s/compose?to=%s@%s", Network, alias, domain)
}
10 changes: 5 additions & 5 deletions integrations/bitpic/bitpic.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Meta struct {
func GetPic(alias, domain string, tracing bool) (response *Response, err error) {

// Set the url for the request
reqURL := fmt.Sprintf("%s/exists/%s@%s", Network, alias, domain)
reqURL := fmt.Sprintf("https://%s/exists/%s@%s", Network, alias, domain)

// Create a Client and start the request
client := resty.New().SetTimeout(defaultGetTimeout * time.Second)
Expand Down Expand Up @@ -121,18 +121,18 @@ func GetPic(alias, domain string, tracing bool) (response *Response, err error)
// Specs: https://bitpic.network/about
func Url(alias, domain string) string {
if len(DefaultImage) > 0 {
return fmt.Sprintf("%s/u/%s@%s?d=%s", Network, alias, domain, DefaultImage)
return fmt.Sprintf("https://%s/u/%s@%s?d=%s", Network, alias, domain, DefaultImage)
}
return fmt.Sprintf("%s/u/%s@%s", Network, alias, domain)
return fmt.Sprintf("https://%s/u/%s@%s", Network, alias, domain)
}

// UrlFromPaymail will return a url for the bitpic avatar using a paymail
// Specs: https://bitpic.network/about
func UrlFromPaymail(paymail string) string {
if len(DefaultImage) > 0 {
return fmt.Sprintf("%s/u/%s?d=%s", Network, paymail, DefaultImage)
return fmt.Sprintf("https://%s/u/%s?d=%s", Network, paymail, DefaultImage)
}
return fmt.Sprintf("%s/u/%s", Network, paymail)
return fmt.Sprintf("https://%s/u/%s", Network, paymail)
}

// Search will perform a search on the BitPic network
Expand Down

0 comments on commit bc8d7ce

Please sign in to comment.