From ba4caffa084d2152495955224f9b337dae97bf88 Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 13:28:02 +0000 Subject: [PATCH 1/7] protonmail: Fetch user addresses using new API. --- protonmail/adresses.go | 1 + protonmail/users.go | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/protonmail/adresses.go b/protonmail/adresses.go index 66e785b..c4b48b2 100644 --- a/protonmail/adresses.go +++ b/protonmail/adresses.go @@ -31,6 +31,7 @@ type Address struct { Receive int Status AddressStatus Type AddressType + Order int DisplayName string Signature string // HTML HasKeys int diff --git a/protonmail/users.go b/protonmail/users.go index dc35b4a..ff4b876 100644 --- a/protonmail/users.go +++ b/protonmail/users.go @@ -70,13 +70,28 @@ func (c *Client) GetCurrentUser() (*User, error) { return nil, err } - var respData struct { + var userData struct { resp User *User } - if err := c.doJSON(req, &respData); err != nil { + if err := c.doJSON(req, &userData); err != nil { return nil, err } - return respData.User, nil + req2, err := c.newRequest(http.MethodGet, "/addresses", nil) + if err != nil { + return nil, err + } + + var addrData struct { + resp + Addresses []*Address + } + if err := c.doJSON(req2, &addrData); err != nil { + return nil, err + } + + userData.User.Addresses = addrData.Addresses + + return userData.User, nil } From 95ee806a93cebe37113196a2e2874d92242048ee Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 13:56:50 +0000 Subject: [PATCH 2/7] smtp: Add sender address to message. Protonmail now expects it. --- smtp/smtp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smtp/smtp.go b/smtp/smtp.go index 13e9818..60a8783 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -95,6 +95,11 @@ func (u *user) Send(from string, to []string, r io.Reader) error { return errors.New("sender address key hasn't been decrypted") } + senderAddress := &protonmail.MessageAddress{ + Address: fromAddr.Email, + Name: fromAddr.DisplayName, + } + msg := &protonmail.Message{ ToList: toPMAddressList(toList), CCList: toPMAddressList(ccList), @@ -102,6 +107,7 @@ func (u *user) Send(from string, to []string, r io.Reader) error { Subject: subject, Header: formatHeader(mr.Header), AddressID: fromAddr.ID, + Sender: senderAddress, } // Create an empty draft From 9a6f7187a5650da94670427b46e14c3d663269d8 Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 14:30:03 +0000 Subject: [PATCH 3/7] protonmail: Update MessagePackageSet BodyKey for new API. --- protonmail/messages.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/protonmail/messages.go b/protonmail/messages.go index 8c79d8e..9c1c85c 100644 --- a/protonmail/messages.go +++ b/protonmail/messages.go @@ -403,7 +403,7 @@ type MessagePackageSet struct { Body string // Encrypted body data packet // Only if cleartext is sent - BodyKey string + BodyKey map[string]string AttachmentKeys map[string]string bodyKey *packet.EncryptedKey @@ -494,8 +494,10 @@ func (set *MessagePackageSet) AddCleartext(addr string) (*MessagePackage, error) set.Addresses[addr] = pkg set.Type |= MessagePackageCleartext - if set.BodyKey == "" || set.AttachmentKeys == nil { - set.BodyKey = base64.StdEncoding.EncodeToString(set.bodyKey.Key) + if set.BodyKey == nil || set.AttachmentKeys == nil { + set.BodyKey = make(map[string]string, 2) + set.BodyKey["Algorithm"] = "aes256" + set.BodyKey["Key"] = base64.StdEncoding.EncodeToString(set.bodyKey.Key) set.AttachmentKeys = make(map[string]string, len(set.attachmentKeys)) for att, key := range set.attachmentKeys { From 71f1167182bc68902e0395f77cddd27bc2890652 Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 14:30:27 +0000 Subject: [PATCH 4/7] protonmail: Change API endpoint for SendMessage. --- protonmail/messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protonmail/messages.go b/protonmail/messages.go index 9c1c85c..62f0bb3 100644 --- a/protonmail/messages.go +++ b/protonmail/messages.go @@ -565,7 +565,7 @@ type OutgoingMessage struct { } func (c *Client) SendMessage(msg *OutgoingMessage) (sent, parent *Message, err error) { - req, err := c.newJSONRequest(http.MethodPost, "/messages/send/"+msg.ID, msg) + req, err := c.newJSONRequest(http.MethodPost, "/messages/"+msg.ID, msg) if err != nil { return nil, nil, err } From deb4662abbae64d9dfba5e848b8050d13e7cbd9f Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 22:06:55 +0000 Subject: [PATCH 5/7] protonmail: Define struct MessageBodyKey. --- protonmail/messages.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/protonmail/messages.go b/protonmail/messages.go index 62f0bb3..89c26e2 100644 --- a/protonmail/messages.go +++ b/protonmail/messages.go @@ -403,7 +403,7 @@ type MessagePackageSet struct { Body string // Encrypted body data packet // Only if cleartext is sent - BodyKey map[string]string + BodyKey *MessageBodyKey `json:omitempty` AttachmentKeys map[string]string bodyKey *packet.EncryptedKey @@ -411,6 +411,11 @@ type MessagePackageSet struct { signature int } +type MessageBodyKey struct { + Algorithm string + Key string +} + func NewMessagePackageSet(attachmentKeys map[string]*packet.EncryptedKey) *MessagePackageSet { return &MessagePackageSet{ Addresses: make(map[string]*MessagePackage), @@ -495,9 +500,10 @@ func (set *MessagePackageSet) AddCleartext(addr string) (*MessagePackage, error) set.Type |= MessagePackageCleartext if set.BodyKey == nil || set.AttachmentKeys == nil { - set.BodyKey = make(map[string]string, 2) - set.BodyKey["Algorithm"] = "aes256" - set.BodyKey["Key"] = base64.StdEncoding.EncodeToString(set.bodyKey.Key) + set.BodyKey = &MessageBodyKey{ + Algorithm: "aes256", + Key: base64.StdEncoding.EncodeToString(set.bodyKey.Key), + } set.AttachmentKeys = make(map[string]string, len(set.attachmentKeys)) for att, key := range set.attachmentKeys { From 05ad63560fe8953afb439601a49be2af9639ef74 Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 22:07:12 +0000 Subject: [PATCH 6/7] protonmail: Re-use local request variable in GetCurrentUser(). --- protonmail/users.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protonmail/users.go b/protonmail/users.go index ff4b876..426f677 100644 --- a/protonmail/users.go +++ b/protonmail/users.go @@ -78,7 +78,7 @@ func (c *Client) GetCurrentUser() (*User, error) { return nil, err } - req2, err := c.newRequest(http.MethodGet, "/addresses", nil) + req, err = c.newRequest(http.MethodGet, "/addresses", nil) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (c *Client) GetCurrentUser() (*User, error) { resp Addresses []*Address } - if err := c.doJSON(req2, &addrData); err != nil { + if err := c.doJSON(req, &addrData); err != nil { return nil, err } From 49160bcd3e3c4f6de3fef1e615ee0f707cea72d3 Mon Sep 17 00:00:00 2001 From: Brandon McDonnell Date: Sat, 20 Oct 2018 22:31:53 +0000 Subject: [PATCH 7/7] protonmail: Fix typo in MessageBodyKey struct. --- protonmail/messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protonmail/messages.go b/protonmail/messages.go index 89c26e2..4e0fa5c 100644 --- a/protonmail/messages.go +++ b/protonmail/messages.go @@ -403,7 +403,7 @@ type MessagePackageSet struct { Body string // Encrypted body data packet // Only if cleartext is sent - BodyKey *MessageBodyKey `json:omitempty` + BodyKey *MessageBodyKey `json:",omitempty"` AttachmentKeys map[string]string bodyKey *packet.EncryptedKey