Rename package, don't serve IMAP
This commit is contained in:
parent
308eec6c69
commit
d4451a8a15
|
@ -13,8 +13,8 @@ import (
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"golang.org/x/crypto/nacl/secretbox"
|
"golang.org/x/crypto/nacl/secretbox"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/config"
|
"github.com/0ranki/hydroxide-push/config"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func authFilePath() (string, error) {
|
func authFilePath() (string, error) {
|
||||||
|
|
|
@ -13,10 +13,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
"github.com/ProtonMail/go-crypto/openpgp"
|
"github.com/ProtonMail/go-crypto/openpgp"
|
||||||
"github.com/emersion/go-vcard"
|
"github.com/emersion/go-vcard"
|
||||||
"github.com/emersion/go-webdav/carddav"
|
"github.com/emersion/go-webdav/carddav"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: use a HTTP error
|
// TODO: use a HTTP error
|
||||||
|
|
|
@ -5,16 +5,15 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/emersion/go-imap"
|
"github.com/0ranki/hydroxide-push/auth"
|
||||||
|
"github.com/0ranki/hydroxide-push/config"
|
||||||
|
"github.com/0ranki/hydroxide-push/events"
|
||||||
|
imapbackend "github.com/0ranki/hydroxide-push/imap"
|
||||||
|
"github.com/0ranki/hydroxide-push/ntfy"
|
||||||
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
imapserver "github.com/emersion/go-imap/server"
|
imapserver "github.com/emersion/go-imap/server"
|
||||||
"github.com/emersion/hydroxide/auth"
|
|
||||||
"github.com/emersion/hydroxide/config"
|
|
||||||
"github.com/emersion/hydroxide/events"
|
|
||||||
imapbackend "github.com/emersion/hydroxide/imap"
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -28,9 +27,7 @@ var (
|
||||||
debug bool
|
debug bool
|
||||||
apiEndpoint string
|
apiEndpoint string
|
||||||
appVersion string
|
appVersion string
|
||||||
|
cfg ntfy.NtfyConfig
|
||||||
//imapUser *backend.User
|
|
||||||
ntfyTopic string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newClient() *protonmail.Client {
|
func newClient() *protonmail.Client {
|
||||||
|
@ -60,7 +57,7 @@ func askPass(prompt string) ([]byte, error) {
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenAndServeIMAP(addr string, debug bool, authManager *auth.Manager, eventsManager *events.Manager, tlsConfig *tls.Config) error {
|
func listenEventsAndNotify(addr string, debug bool, authManager *auth.Manager, eventsManager *events.Manager, tlsConfig *tls.Config) error {
|
||||||
be := imapbackend.New(authManager, eventsManager)
|
be := imapbackend.New(authManager, eventsManager)
|
||||||
s := imapserver.New(be)
|
s := imapserver.New(be)
|
||||||
s.Addr = addr
|
s.Addr = addr
|
||||||
|
@ -69,53 +66,19 @@ func listenAndServeIMAP(addr string, debug bool, authManager *auth.Manager, even
|
||||||
if debug {
|
if debug {
|
||||||
s.Debug = os.Stdout
|
s.Debug = os.Stdout
|
||||||
}
|
}
|
||||||
|
ntfy.Login(&cfg, be)
|
||||||
if s.TLSConfig != nil {
|
log.Println("Listening for events", s.Addr)
|
||||||
log.Println("IMAP server listening with TLS on", s.Addr)
|
for {
|
||||||
return s.ListenAndServeTLS()
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
go func() {
|
return nil
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
c, _ := net.ResolveIPAddr("ip", "127.0.0.1")
|
|
||||||
conn := imap.ConnInfo{
|
|
||||||
RemoteAddr: c,
|
|
||||||
LocalAddr: c,
|
|
||||||
TLS: nil,
|
|
||||||
}
|
|
||||||
usernames, err := auth.ListUsernames()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if len(usernames) > 1 {
|
|
||||||
log.Fatal("only one login supported for now")
|
|
||||||
}
|
|
||||||
if len(usernames) == 0 {
|
|
||||||
executable, _ := os.Executable()
|
|
||||||
log.Fatal("login first using " + executable + " auth <protonmail username>")
|
|
||||||
}
|
|
||||||
// TODO: bridge password
|
|
||||||
_, err = be.Login(&conn, usernames[0], os.Getenv("HYDROXIDE_BRIDGE_PASS"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
log.Println("IMAP server listening on", s.Addr)
|
|
||||||
return s.ListenAndServe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const usage = `usage: hydroxide [options...] <command>
|
const usage = `usage: hydroxide-push [options...] <command>
|
||||||
Commands:
|
Commands:
|
||||||
auth <username> Login to ProtonMail via hydroxide
|
auth <username> Login to ProtonMail via hydroxide
|
||||||
carddav Run hydroxide as a CardDAV server
|
status View hydroxide status
|
||||||
export-secret-keys <username> Export secret keys
|
notify Start the notification daemon
|
||||||
imap Run hydroxide as an IMAP server
|
|
||||||
import-messages <username> [file] Import messages
|
|
||||||
export-messages [options...] <username> Export messages
|
|
||||||
sendmail <username> -- <args...> sendmail(1) interface
|
|
||||||
serve Run all servers
|
|
||||||
smtp Run hydroxide as an SMTP server
|
|
||||||
status View hydroxide status
|
|
||||||
|
|
||||||
Global options:
|
Global options:
|
||||||
-debug
|
-debug
|
||||||
|
@ -124,30 +87,6 @@ Global options:
|
||||||
ProtonMail API endpoint
|
ProtonMail API endpoint
|
||||||
-app-version <version>
|
-app-version <version>
|
||||||
ProtonMail application version
|
ProtonMail application version
|
||||||
-smtp-host example.com
|
|
||||||
Allowed SMTP email hostname on which hydroxide listens, defaults to 127.0.0.1
|
|
||||||
-imap-host example.com
|
|
||||||
Allowed IMAP email hostname on which hydroxide listens, defaults to 127.0.0.1
|
|
||||||
-carddav-host example.com
|
|
||||||
Allowed SMTP email hostname on which hydroxide listens, defaults to 127.0.0.1
|
|
||||||
-smtp-port example.com
|
|
||||||
SMTP port on which hydroxide listens, defaults to 1025
|
|
||||||
-imap-port example.com
|
|
||||||
IMAP port on which hydroxide listens, defaults to 1143
|
|
||||||
-carddav-port example.com
|
|
||||||
CardDAV port on which hydroxide listens, defaults to 8080
|
|
||||||
-disable-imap
|
|
||||||
Disable IMAP for hydroxide serve
|
|
||||||
-disable-smtp
|
|
||||||
Disable SMTP for hydroxide serve
|
|
||||||
-disable-carddav
|
|
||||||
Disable CardDAV for hydroxide serve
|
|
||||||
-tls-cert /path/to/cert.pem
|
|
||||||
Path to the certificate to use for incoming connections (Optional)
|
|
||||||
-tls-key /path/to/key.pem
|
|
||||||
Path to the certificate key to use for incoming connections (Optional)
|
|
||||||
-tls-client-ca /path/to/ca.pem
|
|
||||||
If set, clients must provide a certificate signed by the given CA (Optional)
|
|
||||||
|
|
||||||
Environment variables:
|
Environment variables:
|
||||||
HYDROXIDE_BRIDGE_PASS Don't prompt for the bridge password, use this variable instead
|
HYDROXIDE_BRIDGE_PASS Don't prompt for the bridge password, use this variable instead
|
||||||
|
@ -157,10 +96,6 @@ func main() {
|
||||||
flag.BoolVar(&debug, "debug", false, "Enable debug logs")
|
flag.BoolVar(&debug, "debug", false, "Enable debug logs")
|
||||||
flag.StringVar(&apiEndpoint, "api-endpoint", defaultAPIEndpoint, "ProtonMail API endpoint")
|
flag.StringVar(&apiEndpoint, "api-endpoint", defaultAPIEndpoint, "ProtonMail API endpoint")
|
||||||
flag.StringVar(&appVersion, "app-version", defaultAppVersion, "ProtonMail app version")
|
flag.StringVar(&appVersion, "app-version", defaultAppVersion, "ProtonMail app version")
|
||||||
flag.StringVar(&ntfyTopic, "topic", "", "ntfy.sh/NextPush topic to push notifications to")
|
|
||||||
|
|
||||||
imapHost := "127.0.0.1" // flag.String("imap-host", "127.0.0.1", "Allowed IMAP email hostname on which hydroxide listens, defaults to 127.0.0.1")
|
|
||||||
imapPort := "1143" // flag.String("imap-port", "1143", "IMAP port on which hydroxide listens, defaults to 1143")
|
|
||||||
|
|
||||||
tlsCert := flag.String("tls-cert", "", "Path to the certificate to use for incoming connections")
|
tlsCert := flag.String("tls-cert", "", "Path to the certificate to use for incoming connections")
|
||||||
tlsCertKey := flag.String("tls-key", "", "Path to the certificate key to use for incoming connections")
|
tlsCertKey := flag.String("tls-key", "", "Path to the certificate key to use for incoming connections")
|
||||||
|
@ -294,16 +229,24 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "setup-ntfy":
|
case "setup-ntfy":
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
case "notify":
|
fmt.Printf("Input push server URL (e.g. 'http://ntfy.sh') : ")
|
||||||
if ntfyTopic == "" {
|
scanner.Scan()
|
||||||
log.Fatal("please set ntfy.sh topic using --topic")
|
cfg.URL = scanner.Text()
|
||||||
|
scanner = bufio.NewScanner(os.Stdin)
|
||||||
|
fmt.Printf("Input push topic (e.g. my-proton-notifications)\nLeave blank to generate a random one: ")
|
||||||
|
scanner.Scan()
|
||||||
|
cfg.Topic = scanner.Text()
|
||||||
|
fmt.Printf("Using URL %s\n", cfg.String())
|
||||||
|
err = cfg.Save()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
addr := imapHost + ":" + imapPort
|
log.Println("Notification configuration saved")
|
||||||
|
case "notify":
|
||||||
authManager := auth.NewManager(newClient)
|
authManager := auth.NewManager(newClient)
|
||||||
eventsManager := events.NewManager()
|
eventsManager := events.NewManager()
|
||||||
|
log.Fatal(listenEventsAndNotify("0", debug, authManager, eventsManager, tlsConfig))
|
||||||
log.Fatal(listenAndServeIMAP(addr, debug, authManager, eventsManager, tlsConfig))
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Print(usage)
|
fmt.Print(usage)
|
||||||
|
|
|
@ -18,15 +18,15 @@ import (
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/auth"
|
"github.com/0ranki/hydroxide-push/auth"
|
||||||
"github.com/emersion/hydroxide/carddav"
|
"github.com/0ranki/hydroxide-push/carddav"
|
||||||
"github.com/emersion/hydroxide/config"
|
"github.com/0ranki/hydroxide-push/config"
|
||||||
"github.com/emersion/hydroxide/events"
|
"github.com/0ranki/hydroxide-push/events"
|
||||||
"github.com/emersion/hydroxide/exports"
|
"github.com/0ranki/hydroxide-push/exports"
|
||||||
imapbackend "github.com/emersion/hydroxide/imap"
|
imapbackend "github.com/0ranki/hydroxide-push/imap"
|
||||||
"github.com/emersion/hydroxide/imports"
|
"github.com/0ranki/hydroxide-push/imports"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
smtpbackend "github.com/emersion/hydroxide/smtp"
|
smtpbackend "github.com/0ranki/hydroxide-push/smtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pollInterval = 10 * time.Second
|
const pollInterval = 10 * time.Second
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/emersion/go-message/mail"
|
"github.com/emersion/go-message/mail"
|
||||||
"github.com/emersion/go-message/textproto"
|
"github.com/emersion/go-message/textproto"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeMessage(c *protonmail.Client, privateKeys openpgp.KeyRing, w io.Writer, msg *protonmail.Message) error {
|
func writeMessage(c *protonmail.Client, privateKeys openpgp.KeyRing, w io.Writer, msg *protonmail.Message) error {
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
imapbackend "github.com/emersion/go-imap/backend"
|
imapbackend "github.com/emersion/go-imap/backend"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/auth"
|
"github.com/0ranki/hydroxide-push/auth"
|
||||||
"github.com/emersion/hydroxide/events"
|
"github.com/0ranki/hydroxide-push/events"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNotYetImplemented = errors.New("not yet implemented")
|
var errNotYetImplemented = errors.New("not yet implemented")
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func serializeUID(uid uint32) []byte {
|
func serializeUID(uid uint32) []byte {
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/config"
|
"github.com/0ranki/hydroxide-push/config"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrNotFound = errors.New("message not found in local database")
|
var ErrNotFound = errors.New("message not found in local database")
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
imapbackend "github.com/emersion/go-imap/backend"
|
imapbackend "github.com/emersion/go-imap/backend"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/imap/database"
|
"github.com/0ranki/hydroxide-push/imap/database"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
const delimiter = "/"
|
const delimiter = "/"
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
"github.com/emersion/go-message/mail"
|
"github.com/emersion/go-message/mail"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func messageID(msg *protonmail.Message) string {
|
func messageID(msg *protonmail.Message) string {
|
||||||
|
|
10
imap/user.go
10
imap/user.go
|
@ -1,17 +1,17 @@
|
||||||
package imap
|
package imap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/emersion/hydroxide/ntfy"
|
"github.com/0ranki/hydroxide-push/ntfy"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/0ranki/hydroxide-push/events"
|
||||||
|
"github.com/0ranki/hydroxide-push/imap/database"
|
||||||
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
"github.com/ProtonMail/go-crypto/openpgp"
|
"github.com/ProtonMail/go-crypto/openpgp"
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
imapbackend "github.com/emersion/go-imap/backend"
|
imapbackend "github.com/emersion/go-imap/backend"
|
||||||
"github.com/emersion/hydroxide/events"
|
|
||||||
"github.com/emersion/hydroxide/imap/database"
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var systemMailboxes = []struct {
|
var systemMailboxes = []struct {
|
||||||
|
@ -118,7 +118,7 @@ func newUser(be *backend, username string, c *protonmail.Client, privateKeys ope
|
||||||
go uu.receiveEvents(be.updates, ch)
|
go uu.receiveEvents(be.updates, ch)
|
||||||
uu.eventsReceiver = be.eventsManager.Register(c, u.Name, ch, done)
|
uu.eventsReceiver = be.eventsManager.Register(c, u.Name, ch, done)
|
||||||
|
|
||||||
log.Printf("User %q logged in via IMAP", u.Name)
|
log.Printf("Logged in as user %q", u.Name)
|
||||||
return uu, nil
|
return uu, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
||||||
"github.com/emersion/go-message/mail"
|
"github.com/emersion/go-message/mail"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ImportMessage(c *protonmail.Client, r io.Reader) error {
|
func ImportMessage(c *protonmail.Client, r io.Reader) error {
|
||||||
|
|
95
ntfy/ntfy.go
95
ntfy/ntfy.go
|
@ -1,10 +1,46 @@
|
||||||
package ntfy
|
package ntfy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/0ranki/hydroxide-push/auth"
|
||||||
|
"github.com/0ranki/hydroxide-push/config"
|
||||||
|
"github.com/emersion/go-imap"
|
||||||
|
"github.com/emersion/go-imap/backend"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type NtfyConfig struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Topic string `json:"topic"`
|
||||||
|
BridgePw string `json:"bridgePw"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *NtfyConfig) String() string {
|
||||||
|
return fmt.Sprintf("%s/%s", cfg.URL, cfg.Topic)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *NtfyConfig) Save() error {
|
||||||
|
b, err := json.Marshal(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path, err := ntfyConfigFile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.WriteFile(path, b, 0600)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ntfyConfigFile() (string, error) {
|
||||||
|
return config.Path("notify.json")
|
||||||
|
}
|
||||||
|
|
||||||
func Notify() {
|
func Notify() {
|
||||||
req, _ := http.NewRequest("POST", "https://push.oranki.net/testing20240325", strings.NewReader("New message received"))
|
req, _ := http.NewRequest("POST", "https://push.oranki.net/testing20240325", strings.NewReader("New message received"))
|
||||||
req.Header.Set("Title", "ProtoMail")
|
req.Header.Set("Title", "ProtoMail")
|
||||||
|
@ -12,3 +48,62 @@ func Notify() {
|
||||||
req.Header.Set("Tags", "envelope")
|
req.Header.Set("Tags", "envelope")
|
||||||
http.DefaultClient.Do(req)
|
http.DefaultClient.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cfg *NtfyConfig) Read() error {
|
||||||
|
f, err := ntfyConfigFile()
|
||||||
|
if err == nil {
|
||||||
|
b, err := os.ReadFile(f)
|
||||||
|
if err == nil {
|
||||||
|
err = json.Unmarshal(b, &cfg)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Login(cfg *NtfyConfig, be backend.Backend) {
|
||||||
|
//time.Sleep(1 * time.Second)
|
||||||
|
c, _ := net.ResolveIPAddr("ip", "127.0.0.1")
|
||||||
|
conn := imap.ConnInfo{
|
||||||
|
RemoteAddr: c,
|
||||||
|
LocalAddr: c,
|
||||||
|
TLS: nil,
|
||||||
|
}
|
||||||
|
usernames, err := auth.ListUsernames()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(usernames) > 1 {
|
||||||
|
log.Fatal("only one login supported for now")
|
||||||
|
}
|
||||||
|
err = cfg.Read()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
if len(usernames) == 0 || cfg.URL == "" || cfg.Topic == "" {
|
||||||
|
executable, _ := os.Executable()
|
||||||
|
log.Println("login first using " + executable + " auth <protonmail username>")
|
||||||
|
log.Fatalln("then setup ntfy using " + executable + "setup-ntfy")
|
||||||
|
}
|
||||||
|
cfg.BridgePw = os.Getenv("HYDROXIDE_BRIDGE_PASSWORD")
|
||||||
|
if cfg.BridgePw == "" {
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
fmt.Printf("Bridge password: ")
|
||||||
|
scanner.Scan()
|
||||||
|
cfg.BridgePw = scanner.Text()
|
||||||
|
scanner = bufio.NewScanner(os.Stdin)
|
||||||
|
fmt.Printf("Save password to config? The password is stored in plain text! (yes/n): ")
|
||||||
|
scanner.Scan()
|
||||||
|
if scanner.Text() == "yes" {
|
||||||
|
if err = cfg.Save(); err != nil {
|
||||||
|
log.Fatal("failed to save notification config")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = be.Login(&conn, usernames[0], cfg.BridgePw)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ import (
|
||||||
"github.com/emersion/go-sasl"
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/auth"
|
"github.com/0ranki/hydroxide-push/auth"
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
"github.com/0ranki/hydroxide-push/protonmail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toPMAddressList(addresses []*mail.Address) []*protonmail.MessageAddress {
|
func toPMAddressList(addresses []*mail.Address) []*protonmail.MessageAddress {
|
||||||
|
|
Loading…
Reference in New Issue