go fmt
This commit is contained in:
parent
16a9952616
commit
a3c439da70
|
@ -9,9 +9,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/hydroxide/protonmail"
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
type contextKey string
|
type contextKey string
|
||||||
|
@ -62,7 +62,7 @@ func (fi *addressFileInfo) Sys() interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressObject struct {
|
type addressObject struct {
|
||||||
c *protonmail.Client
|
c *protonmail.Client
|
||||||
contact *protonmail.Contact
|
contact *protonmail.Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,16 +118,16 @@ func (ao *addressObject) SetCard(card vcard.Card) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressBook struct {
|
type addressBook struct {
|
||||||
c *protonmail.Client
|
c *protonmail.Client
|
||||||
cache map[string]*addressObject
|
cache map[string]*addressObject
|
||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
total int
|
total int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ab *addressBook) Info() (*carddav.AddressBookInfo, error) {
|
func (ab *addressBook) Info() (*carddav.AddressBookInfo, error) {
|
||||||
return &carddav.AddressBookInfo{
|
return &carddav.AddressBookInfo{
|
||||||
Name: "ProtonMail",
|
Name: "ProtonMail",
|
||||||
Description: "ProtonMail contacts",
|
Description: "ProtonMail contacts",
|
||||||
MaxResourceSize: 100 * 1024,
|
MaxResourceSize: 100 * 1024,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func (ab *addressBook) ListAddressObjects() ([]carddav.AddressObject, error) {
|
||||||
for _, contact := range contacts {
|
for _, contact := range contacts {
|
||||||
if _, ok := ab.addressObject(contact.ID); !ok {
|
if _, ok := ab.addressObject(contact.ID); !ok {
|
||||||
ab.cacheAddressObject(&addressObject{
|
ab.cacheAddressObject(&addressObject{
|
||||||
c: ab.c,
|
c: ab.c,
|
||||||
contact: contact,
|
contact: contact,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ func (ab *addressBook) ListAddressObjects() ([]carddav.AddressObject, error) {
|
||||||
ao, ok := ab.addressObject(contact.ID)
|
ao, ok := ab.addressObject(contact.ID)
|
||||||
if !ok {
|
if !ok {
|
||||||
ao = &addressObject{
|
ao = &addressObject{
|
||||||
c: ab.c,
|
c: ab.c,
|
||||||
contact: &protonmail.Contact{ID: contact.ID},
|
contact: &protonmail.Contact{ID: contact.ID},
|
||||||
}
|
}
|
||||||
ab.cacheAddressObject(ao)
|
ab.cacheAddressObject(ao)
|
||||||
|
@ -233,7 +233,7 @@ func (ab *addressBook) GetAddressObject(id string) (carddav.AddressObject, error
|
||||||
}
|
}
|
||||||
|
|
||||||
ao := &addressObject{
|
ao := &addressObject{
|
||||||
c: ab.c,
|
c: ab.c,
|
||||||
contact: contact,
|
contact: contact,
|
||||||
}
|
}
|
||||||
ab.cacheAddressObject(ao)
|
ab.cacheAddressObject(ao)
|
||||||
|
@ -261,7 +261,7 @@ func (ab *addressBook) CreateAddressObject(card vcard.Card) (carddav.AddressObje
|
||||||
contact.Cards = contactImport.Cards // Not returned by the server
|
contact.Cards = contactImport.Cards // Not returned by the server
|
||||||
|
|
||||||
ao := &addressObject{
|
ao := &addressObject{
|
||||||
c: ab.c,
|
c: ab.c,
|
||||||
contact: contact,
|
contact: contact,
|
||||||
}
|
}
|
||||||
ab.cacheAddressObject(ao)
|
ab.cacheAddressObject(ao)
|
||||||
|
@ -282,7 +282,7 @@ func (ab *addressBook) receiveEvents(events <-chan *protonmail.Event) {
|
||||||
fallthrough
|
fallthrough
|
||||||
case protonmail.EventUpdate:
|
case protonmail.EventUpdate:
|
||||||
ab.cache[eventContact.ID] = &addressObject{
|
ab.cache[eventContact.ID] = &addressObject{
|
||||||
c: ab.c,
|
c: ab.c,
|
||||||
contact: eventContact.Contact,
|
contact: eventContact.Contact,
|
||||||
}
|
}
|
||||||
case protonmail.EventDelete:
|
case protonmail.EventDelete:
|
||||||
|
@ -297,7 +297,7 @@ func (ab *addressBook) receiveEvents(events <-chan *protonmail.Event) {
|
||||||
|
|
||||||
func NewHandler(c *protonmail.Client, events <-chan *protonmail.Event) http.Handler {
|
func NewHandler(c *protonmail.Client, events <-chan *protonmail.Event) http.Handler {
|
||||||
ab := &addressBook{
|
ab := &addressBook{
|
||||||
c: c,
|
c: c,
|
||||||
cache: make(map[string]*addressObject),
|
cache: make(map[string]*addressObject),
|
||||||
total: -1,
|
total: -1,
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ const authFile = "auth.json"
|
||||||
|
|
||||||
type cachedAuth struct {
|
type cachedAuth struct {
|
||||||
protonmail.Auth
|
protonmail.Auth
|
||||||
LoginPassword string
|
LoginPassword string
|
||||||
MailboxPassword string
|
MailboxPassword string
|
||||||
// TODO: add padding
|
// TODO: add padding
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func receiveEvents(c *protonmail.Client, last string, ch chan<- *protonmail.Even
|
||||||
}
|
}
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
h http.Handler
|
h http.Handler
|
||||||
hashedSecretKey []byte
|
hashedSecretKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ func main() {
|
||||||
sessions := make(map[string]*session)
|
sessions := make(map[string]*session)
|
||||||
|
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: "127.0.0.1:"+port,
|
Addr: "127.0.0.1:" + port,
|
||||||
Handler: http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
Handler: http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||||
resp.Header().Set("WWW-Authenticate", "Basic")
|
resp.Header().Set("WWW-Authenticate", "Basic")
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ func main() {
|
||||||
h = carddav.NewHandler(c, events)
|
h = carddav.NewHandler(c, events)
|
||||||
|
|
||||||
sessions[username] = &session{
|
sessions[username] = &session{
|
||||||
h: h,
|
h: h,
|
||||||
hashedSecretKey: hashed,
|
hashedSecretKey: hashed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package protonmail
|
package protonmail
|
||||||
|
|
||||||
type (
|
type (
|
||||||
AddressSend int
|
AddressSend int
|
||||||
AddressStatus int
|
AddressStatus int
|
||||||
AddressType int
|
AddressType int
|
||||||
)
|
)
|
||||||
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
ID string
|
ID string
|
||||||
DomainID string
|
DomainID string
|
||||||
Email string
|
Email string
|
||||||
Send AddressSend
|
Send AddressSend
|
||||||
Receive int
|
Receive int
|
||||||
Status AddressStatus
|
Status AddressStatus
|
||||||
Type AddressType
|
Type AddressType
|
||||||
DisplayName string
|
DisplayName string
|
||||||
Signature string // HTML
|
Signature string // HTML
|
||||||
HasKeys int
|
HasKeys int
|
||||||
Keys []*Key
|
Keys []*Key
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
ID string `json:"EventID"`
|
ID string `json:"EventID"`
|
||||||
Refresh int
|
Refresh int
|
||||||
//Messages
|
//Messages
|
||||||
Contacts []*EventContact
|
Contacts []*EventContact
|
||||||
|
@ -30,8 +30,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type EventContact struct {
|
type EventContact struct {
|
||||||
ID string
|
ID string
|
||||||
Action EventAction
|
Action EventAction
|
||||||
Contact *Contact
|
Contact *Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package protonmail
|
package protonmail
|
||||||
|
|
||||||
type Key struct {
|
type Key struct {
|
||||||
ID string
|
ID string
|
||||||
Version int
|
Version int
|
||||||
PublicKey string
|
PublicKey string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
Fingerprint string
|
Fingerprint string
|
||||||
Activation interface{} // TODO
|
Activation interface{} // TODO
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,63 +5,63 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
LogAuth int
|
LogAuth int
|
||||||
ComposerMode int
|
ComposerMode int
|
||||||
MessageButtons int
|
MessageButtons int
|
||||||
ImagesMode int
|
ImagesMode int
|
||||||
ViewMode int
|
ViewMode int
|
||||||
ViewLayout int
|
ViewLayout int
|
||||||
SwipeAction int
|
SwipeAction int
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
NotificationEmail string
|
NotificationEmail string
|
||||||
Signature string // HTML
|
Signature string // HTML
|
||||||
NumMessagePerPage int
|
NumMessagePerPage int
|
||||||
UsedSpace int
|
UsedSpace int
|
||||||
Notify int
|
Notify int
|
||||||
AutoSaveContacts int
|
AutoSaveContacts int
|
||||||
Language string // e.g. en_US
|
Language string // e.g. en_US
|
||||||
LogAuth LogAuth
|
LogAuth LogAuth
|
||||||
ComposerMode ComposerMode
|
ComposerMode ComposerMode
|
||||||
MessageButtons MessageButtons
|
MessageButtons MessageButtons
|
||||||
Images ImagesMode
|
Images ImagesMode
|
||||||
Moved int
|
Moved int
|
||||||
ShowImages int
|
ShowImages int
|
||||||
ShowEmbedded int
|
ShowEmbedded int
|
||||||
ViewMode ViewMode
|
ViewMode ViewMode
|
||||||
ViewLayout ViewLayout
|
ViewLayout ViewLayout
|
||||||
SwipeLeft SwipeAction
|
SwipeLeft SwipeAction
|
||||||
SwipeRight SwipeAction
|
SwipeRight SwipeAction
|
||||||
Theme string
|
Theme string
|
||||||
Currency string // e.g. EUR
|
Currency string // e.g. EUR
|
||||||
Credit int
|
Credit int
|
||||||
InvoiceText string
|
InvoiceText string
|
||||||
AlsoArchive int
|
AlsoArchive int
|
||||||
Hotkeys int
|
Hotkeys int
|
||||||
PMSignature int
|
PMSignature int
|
||||||
TwoFactor int
|
TwoFactor int
|
||||||
PasswordReset int
|
PasswordReset int
|
||||||
PasswordMode PasswordMode
|
PasswordMode PasswordMode
|
||||||
News int
|
News int
|
||||||
AutoResponder interface{} // TODO
|
AutoResponder interface{} // TODO
|
||||||
AutoWildcardSearch int
|
AutoWildcardSearch int
|
||||||
DraftMIMEType string
|
DraftMIMEType string
|
||||||
ReceiveMIMEType string
|
ReceiveMIMEType string
|
||||||
ImageProxy int
|
ImageProxy int
|
||||||
DisplayName string
|
DisplayName string
|
||||||
MaxSpace int
|
MaxSpace int
|
||||||
MaxUpload int
|
MaxUpload int
|
||||||
Subscribed int // TODO
|
Subscribed int // TODO
|
||||||
Services int // TODO
|
Services int // TODO
|
||||||
Role int // TODO
|
Role int // TODO
|
||||||
Private int
|
Private int
|
||||||
VPN interface{} // TODO
|
VPN interface{} // TODO
|
||||||
Delinquent int
|
Delinquent int
|
||||||
Addresses []*Address
|
Addresses []*Address
|
||||||
Keys []*Key
|
Keys []*Key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetCurrentUser() (*User, error) {
|
func (c *Client) GetCurrentUser() (*User, error) {
|
||||||
|
|
Loading…
Reference in New Issue