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