protonmail: introduce Timestamp
This commit is contained in:
parent
524e2fc323
commit
0e0fb0c38e
|
@ -11,7 +11,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/emersion/go-vcard"
|
"github.com/emersion/go-vcard"
|
||||||
"github.com/emersion/go-webdav/carddav"
|
"github.com/emersion/go-webdav/carddav"
|
||||||
|
@ -125,7 +124,7 @@ func (b *backend) toAddressObject(contact *protonmail.Contact, req *carddav.Addr
|
||||||
|
|
||||||
return &carddav.AddressObject{
|
return &carddav.AddressObject{
|
||||||
Path: formatAddressObjectPath(contact.ID),
|
Path: formatAddressObjectPath(contact.ID),
|
||||||
ModTime: time.Unix(contact.ModifyTime, 0),
|
ModTime: contact.ModifyTime.Time(),
|
||||||
// TODO: stronger ETag
|
// TODO: stronger ETag
|
||||||
ETag: fmt.Sprintf("%x%x", contact.ModifyTime, contact.Size),
|
ETag: fmt.Sprintf("%x%x", contact.ModifyTime, contact.Size),
|
||||||
Card: card,
|
Card: card,
|
||||||
|
|
|
@ -234,7 +234,7 @@ func (mbox *mailbox) fetchMessage(isUid bool, id uint32, items []imap.FetchItem)
|
||||||
case imap.FetchFlags:
|
case imap.FetchFlags:
|
||||||
fetched.Flags = mbox.fetchFlags(msg)
|
fetched.Flags = mbox.fetchFlags(msg)
|
||||||
case imap.FetchInternalDate:
|
case imap.FetchInternalDate:
|
||||||
fetched.InternalDate = time.Unix(msg.Time, 0)
|
fetched.InternalDate = msg.Time.Time()
|
||||||
case imap.FetchRFC822Size:
|
case imap.FetchRFC822Size:
|
||||||
fetched.Size = uint32(msg.Size)
|
fetched.Size = uint32(msg.Size)
|
||||||
case imap.FetchUid:
|
case imap.FetchUid:
|
||||||
|
@ -342,7 +342,7 @@ func (mbox *mailbox) SearchMessages(isUID bool, c *imap.SearchCriteria) ([]uint3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
date := time.Unix(msg.Time, 0).Round(24 * time.Hour)
|
date := msg.Time.Time().Round(24 * time.Hour)
|
||||||
if !c.Since.IsZero() && !date.After(c.Since) {
|
if !c.Since.IsZero() && !date.After(c.Since) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
|
@ -68,7 +67,7 @@ func imapAddressList(addresses []*protonmail.MessageAddress) []*imap.Address {
|
||||||
|
|
||||||
func fetchEnvelope(msg *protonmail.Message) *imap.Envelope {
|
func fetchEnvelope(msg *protonmail.Message) *imap.Envelope {
|
||||||
return &imap.Envelope{
|
return &imap.Envelope{
|
||||||
Date: time.Unix(msg.Time, 0),
|
Date: msg.Time.Time(),
|
||||||
Subject: msg.Subject,
|
Subject: msg.Subject,
|
||||||
From: []*imap.Address{imapAddress(msg.Sender)},
|
From: []*imap.Address{imapAddress(msg.Sender)},
|
||||||
// TODO: Sender
|
// TODO: Sender
|
||||||
|
@ -212,7 +211,7 @@ func mailAddressList(addresses []*protonmail.MessageAddress) []*mail.Address {
|
||||||
func messageHeader(msg *protonmail.Message) message.Header {
|
func messageHeader(msg *protonmail.Message) message.Header {
|
||||||
var h mail.Header
|
var h mail.Header
|
||||||
h.SetContentType("multipart/mixed", nil)
|
h.SetContentType("multipart/mixed", nil)
|
||||||
h.SetDate(time.Unix(msg.Time, 0))
|
h.SetDate(msg.Time.Time())
|
||||||
h.SetSubject(msg.Subject)
|
h.SetSubject(msg.Subject)
|
||||||
h.SetAddressList("From", []*mail.Address{mailAddress(msg.Sender)})
|
h.SetAddressList("From", []*mail.Address{mailAddress(msg.Sender)})
|
||||||
if len(msg.ReplyTos) > 0 {
|
if len(msg.ReplyTos) > 0 {
|
||||||
|
|
|
@ -23,8 +23,8 @@ type CalendarEvent struct {
|
||||||
ID string
|
ID string
|
||||||
CalendarID string
|
CalendarID string
|
||||||
CalendarKeyPacket string
|
CalendarKeyPacket string
|
||||||
CreateTime int64
|
CreateTime Timestamp
|
||||||
LastEditTime int64
|
LastEditTime Timestamp
|
||||||
Author string
|
Author string
|
||||||
Permissions CalendarEventPermissions
|
Permissions CalendarEventPermissions
|
||||||
SharedKeyPacket string
|
SharedKeyPacket string
|
||||||
|
|
|
@ -18,8 +18,8 @@ type Contact struct {
|
||||||
Name string
|
Name string
|
||||||
UID string
|
UID string
|
||||||
Size int
|
Size int
|
||||||
CreateTime int64
|
CreateTime Timestamp
|
||||||
ModifyTime int64
|
ModifyTime Timestamp
|
||||||
LabelIDs []string
|
LabelIDs []string
|
||||||
|
|
||||||
// Not when using ListContacts
|
// Not when using ListContacts
|
||||||
|
|
|
@ -53,7 +53,7 @@ type EventMessage struct {
|
||||||
type EventMessageUpdate struct {
|
type EventMessageUpdate struct {
|
||||||
Unread *int
|
Unread *int
|
||||||
Type *MessageType
|
Type *MessageType
|
||||||
Time int64
|
Time Timestamp
|
||||||
IsReplied *int
|
IsReplied *int
|
||||||
IsRepliedAll *int
|
IsRepliedAll *int
|
||||||
IsForwarded *int
|
IsForwarded *int
|
||||||
|
|
|
@ -62,11 +62,11 @@ type Message struct {
|
||||||
Type MessageType
|
Type MessageType
|
||||||
Sender *MessageAddress
|
Sender *MessageAddress
|
||||||
ToList []*MessageAddress
|
ToList []*MessageAddress
|
||||||
Time int64
|
Time Timestamp
|
||||||
Size int64
|
Size int64
|
||||||
NumAttachments int
|
NumAttachments int
|
||||||
IsEncrypted MessageEncryption
|
IsEncrypted MessageEncryption
|
||||||
ExpirationTime int64
|
ExpirationTime Timestamp
|
||||||
IsReplied int
|
IsReplied int
|
||||||
IsRepliedAll int
|
IsRepliedAll int
|
||||||
IsForwarded int
|
IsForwarded int
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
"golang.org/x/crypto/openpgp"
|
||||||
|
|
||||||
|
@ -51,6 +52,12 @@ func (err *APIError) Error() string {
|
||||||
return fmt.Sprintf("[%v] %v", err.Code, err.Message)
|
return fmt.Sprintf("[%v] %v", err.Code, err.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Timestamp int64
|
||||||
|
|
||||||
|
func (t Timestamp) Time() time.Time {
|
||||||
|
return time.Unix(int64(t), 0)
|
||||||
|
}
|
||||||
|
|
||||||
// Client is a ProtonMail API client.
|
// Client is a ProtonMail API client.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
RootURL string
|
RootURL string
|
||||||
|
|
Loading…
Reference in New Issue