Documentation ¶
Overview ¶
Package protonmail implements a ProtonMail API client.
Index ¶
- Constants
- type APIError
- type Address
- type AddressSend
- type AddressStatus
- type AddressType
- type Attachment
- func (att *Attachment) Encrypt(ciphertext io.Writer, signed *openpgp.Entity) (cleartext io.WriteCloser, err error)
- func (att *Attachment) GenerateKey(to []*openpgp.Entity) (*packet.EncryptedKey, error)
- func (att *Attachment) Read(ciphertext io.Reader, keyring openpgp.KeyRing, prompt openpgp.PromptFunction) (*openpgp.MessageDetails, error)
- type AttachmentKey
- type Auth
- type AuthInfo
- type AuthInfoResp
- type Calendar
- type CalendarEvent
- type CalendarEventCard
- type CalendarEventCardType
- type CalendarEventFilter
- type CalendarEventPermissions
- type CalendarFlags
- type Client
- func (c *Client) Auth(username, password string, info *AuthInfo) (*Auth, error)
- func (c *Client) AuthInfo(username string) (*AuthInfo, error)
- func (c *Client) AuthRefresh(expiredAuth *Auth) (*Auth, error)
- func (c *Client) AuthTOTP(code string) (scope string, err error)
- func (c *Client) CountMessages(address string) ([]*MessageCount, error)
- func (c *Client) CreateAttachment(att *Attachment, r io.Reader) (created *Attachment, err error)
- func (c *Client) CreateContacts(contacts []*ContactImport) ([]*CreateContactResp, error)
- func (c *Client) CreateDraftMessage(msg *Message, parentID string) (*Message, error)
- func (c *Client) DeleteAllContacts() error
- func (c *Client) DeleteContacts(ids []string) ([]*DeleteContactResp, error)
- func (c *Client) DeleteMessages(ids []string) error
- func (c *Client) GetAttachment(id string) (io.ReadCloser, error)
- func (c *Client) GetContact(id string) (*Contact, error)
- func (c *Client) GetConversation(id, msgID string) (*Conversation, []*Message, error)
- func (c *Client) GetCurrentUser() (*User, error)
- func (c *Client) GetEvent(last string) (*Event, error)
- func (c *Client) GetMessage(id string) (*Message, error)
- func (c *Client) GetPublicKeys(email string) (*PublicKeyResp, error)
- func (c *Client) Import(metadata map[string]*Message) (*Importer, error)
- func (c *Client) LabelMessages(labelID string, ids []string) error
- func (c *Client) ListAddresses() ([]*Address, error)
- func (c *Client) ListCalendarEvents(calendarID string, filter *CalendarEventFilter) ([]*CalendarEvent, error)
- func (c *Client) ListCalendars(page, pageSize int) ([]*Calendar, error)
- func (c *Client) ListContacts(page, pageSize int) (total int, contacts []*Contact, err error)
- func (c *Client) ListContactsEmails(page, pageSize int) (total int, emails []*ContactEmail, err error)
- func (c *Client) ListContactsExport(page, pageSize int) (total int, contacts []*ContactExport, err error)
- func (c *Client) ListKeySalts() (map[string][]byte, error)
- func (c *Client) ListLabels() ([]*Label, error)
- func (c *Client) ListMessages(filter *MessageFilter) (total int, messages []*Message, err error)
- func (c *Client) Logout() error
- func (c *Client) MarkMessagesRead(ids []string) error
- func (c *Client) MarkMessagesUnread(ids []string) error
- func (c *Client) SendMessage(msg *OutgoingMessage) (sent, parent *Message, err error)
- func (c *Client) UndeleteMessages(ids []string) error
- func (c *Client) UnlabelMessages(labelID string, ids []string) error
- func (c *Client) Unlock(auth *Auth, keySalts map[string][]byte, passphrase string) (openpgp.EntityList, error)
- func (c *Client) UpdateContact(id string, contact *ContactImport) (*Contact, error)
- func (c *Client) UpdateDraftMessage(msg *Message) (*Message, error)
- type Contact
- type ContactCard
- type ContactCardType
- type ContactEmail
- type ContactEmailDefaults
- type ContactExport
- type ContactImport
- type Conversation
- type CreateContactResp
- type DeleteContactResp
- type Event
- type EventAction
- type EventContact
- type EventMessage
- type EventMessageUpdate
- type EventRefresh
- type ImportMessageResult
- type ImportResult
- type Importer
- type Label
- type LabelType
- type Message
- type MessageAction
- type MessageAddress
- type MessageCount
- type MessageEncryption
- type MessageFilter
- type MessageKeyPacket
- type MessagePackage
- type MessagePackageSet
- type MessagePackageType
- type MessageType
- type OutgoingMessage
- type PackedKey
- type PasswordMode
- type PrivateKey
- type PrivateKeyFlags
- type PublicKey
- type PublicKeyResp
- type RawAPIError
- type RecipientType
- type Timestamp
- type User
Constants ¶
const ( LabelInbox = "0" LabelAllDraft = "1" LabelAllSent = "2" LabelTrash = "3" LabelSpam = "4" LabelAllMail = "5" LabelArchive = "6" LabelSent = "7" LabelDraft = "8" LabelStarred = "10" )
const ( MessagePackageInternal MessagePackageType = 1 MessagePackageEncryptedOutside = 2 MessagePackageCleartext = 4 MessagePackageInlinePGP = 8 MessagePackagePGPMIME = 16 MessagePackageMIME = 32 )
const Version = 3
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct { ID string DomainID string Email string Send AddressSend Receive int Status AddressStatus Type AddressType Order int64 DisplayName string Signature string // HTML HasKeys int Keys []*PrivateKey }
type AddressSend ¶
type AddressSend int
const ( AddressSendDisabled AddressSend = iota AddressSendPrimary AddressSendSecondary )
type AddressStatus ¶
type AddressStatus int
const ( AddressDisabled AddressStatus = iota AddressEnabled )
type AddressType ¶
type AddressType int
const ( AddressOriginal AddressType = iota AddressAlias AddressCustom )
type Attachment ¶
type Attachment struct { ID string MessageID string Name string Size int MIMEType string ContentID string KeyPackets string // encrypted with the user's key, base64-encoded //Headers map[string]string Signature string // contains filtered or unexported fields }
func (*Attachment) Encrypt ¶
func (att *Attachment) Encrypt(ciphertext io.Writer, signed *openpgp.Entity) (cleartext io.WriteCloser, err error)
Encrypt encrypts to w the data that will be written to the returned io.WriteCloser.
Prior to calling Encrypt, an attachment key must have been generated with GenerateKey.
signed is ignored for now.
func (*Attachment) GenerateKey ¶
func (att *Attachment) GenerateKey(to []*openpgp.Entity) (*packet.EncryptedKey, error)
GenerateKey generates an encrypted key and encrypts it to the provided recipients. Usually, the recipient is the user himself.
The returned key is NOT encrypted.
func (*Attachment) Read ¶
func (att *Attachment) Read(ciphertext io.Reader, keyring openpgp.KeyRing, prompt openpgp.PromptFunction) (*openpgp.MessageDetails, error)
type AttachmentKey ¶
type AuthInfoResp ¶
type CalendarEvent ¶ added in v0.2.15
type CalendarEvent struct { ID string CalendarID string CalendarKeyPacket string CreateTime Timestamp LastEditTime Timestamp Author string Permissions CalendarEventPermissions CalendarEvents interface{} PersonalEvent []CalendarEventCard }
type CalendarEventCard ¶ added in v0.2.15
type CalendarEventCard struct { Type CalendarEventCardType Data string Signature string MemberID string }
type CalendarEventCardType ¶ added in v0.2.15
type CalendarEventCardType int
type CalendarEventFilter ¶ added in v0.2.15
type CalendarEventPermissions ¶ added in v0.2.15
type CalendarEventPermissions int
type CalendarFlags ¶ added in v0.2.15
type CalendarFlags int
type Client ¶
type Client struct { RootURL string AppVersion string Debug bool HTTPClient *http.Client ReAuth func() error // contains filtered or unexported fields }
Client is a ProtonMail API client.
func (*Client) CountMessages ¶
func (c *Client) CountMessages(address string) ([]*MessageCount, error)
func (*Client) CreateAttachment ¶
func (c *Client) CreateAttachment(att *Attachment, r io.Reader) (created *Attachment, err error)
CreateAttachment uploads a new attachment. r must be an PGP data packet encrypted with att.KeyPackets.
func (*Client) CreateContacts ¶
func (c *Client) CreateContacts(contacts []*ContactImport) ([]*CreateContactResp, error)
func (*Client) CreateDraftMessage ¶
CreateDraftMessage creates a new draft message. ToList, CCList, BCCList, Subject, Body and AddressID are required in msg.
func (*Client) DeleteAllContacts ¶
func (*Client) DeleteContacts ¶
func (c *Client) DeleteContacts(ids []string) ([]*DeleteContactResp, error)
func (*Client) DeleteMessages ¶
func (*Client) GetAttachment ¶
func (c *Client) GetAttachment(id string) (io.ReadCloser, error)
GetAttachment downloads an attachment's payload. The returned io.ReadCloser may be encrypted, use Attachment.Read to decrypt it.
func (*Client) GetConversation ¶ added in v0.2.16
func (c *Client) GetConversation(id, msgID string) (*Conversation, []*Message, error)
func (*Client) GetCurrentUser ¶
func (*Client) GetPublicKeys ¶
func (c *Client) GetPublicKeys(email string) (*PublicKeyResp, error)
GetPublicKeys retrieves public keys for a user.
func (*Client) ListAddresses ¶
func (*Client) ListCalendarEvents ¶ added in v0.2.15
func (c *Client) ListCalendarEvents(calendarID string, filter *CalendarEventFilter) ([]*CalendarEvent, error)
func (*Client) ListCalendars ¶ added in v0.2.15
func (*Client) ListContacts ¶
func (*Client) ListContactsEmails ¶
func (c *Client) ListContactsEmails(page, pageSize int) (total int, emails []*ContactEmail, err error)
func (*Client) ListContactsExport ¶
func (c *Client) ListContactsExport(page, pageSize int) (total int, contacts []*ContactExport, err error)
func (*Client) ListKeySalts ¶ added in v0.2.9
func (*Client) ListLabels ¶ added in v0.2.13
func (*Client) ListMessages ¶
func (c *Client) ListMessages(filter *MessageFilter) (total int, messages []*Message, err error)
func (*Client) MarkMessagesRead ¶
func (*Client) MarkMessagesUnread ¶
func (*Client) SendMessage ¶
func (c *Client) SendMessage(msg *OutgoingMessage) (sent, parent *Message, err error)
func (*Client) UndeleteMessages ¶
func (*Client) UnlabelMessages ¶
func (*Client) UpdateContact ¶
func (c *Client) UpdateContact(id string, contact *ContactImport) (*Contact, error)
type Contact ¶
type Contact struct { ID string Name string UID string Size int CreateTime Timestamp ModifyTime Timestamp LabelIDs []string // Not when using ListContacts ContactEmails []*ContactEmail Cards []*ContactCard }
type ContactCard ¶
type ContactCard struct { Type ContactCardType Data string Signature string }
func NewEncryptedContactCard ¶
func NewSignedContactCard ¶
func (*ContactCard) Read ¶
func (card *ContactCard) Read(keyring openpgp.KeyRing) (*openpgp.MessageDetails, error)
type ContactCardType ¶
type ContactCardType int
const ( ContactCardCleartext ContactCardType = iota ContactCardEncrypted ContactCardSigned ContactCardEncryptedAndSigned )
func (ContactCardType) Encrypted ¶
func (t ContactCardType) Encrypted() bool
func (ContactCardType) Signed ¶
func (t ContactCardType) Signed() bool
type ContactEmail ¶
type ContactEmailDefaults ¶
type ContactEmailDefaults int
type ContactExport ¶
type ContactExport struct { ID string Cards []*ContactCard }
type ContactImport ¶
type ContactImport struct {
Cards []*ContactCard
}
type Conversation ¶ added in v0.2.16
type CreateContactResp ¶
type CreateContactResp struct { Index int Response struct { Contact *Contact // contains filtered or unexported fields } }
func (*CreateContactResp) Err ¶
func (resp *CreateContactResp) Err() error
type DeleteContactResp ¶
type DeleteContactResp struct { ID string Response struct { // contains filtered or unexported fields } }
func (*DeleteContactResp) Err ¶
func (resp *DeleteContactResp) Err() error
type Event ¶
type Event struct { ID string `json:"EventID"` Refresh EventRefresh Messages []*EventMessage Contacts []*EventContact //ContactEmails //Labels //User //Members //Domains //Organization MessageCounts []*MessageCount //ConversationCounts //UsedSpace Notices []string }
type EventAction ¶
type EventAction int
const ( EventDelete EventAction = iota EventCreate EventUpdate // For messages EventUpdateFlags )
type EventContact ¶
type EventContact struct { ID string Action EventAction Contact *Contact }
type EventMessage ¶
type EventMessage struct { ID string Action EventAction // Only populated for EventCreate Created *Message // Only populated for EventUpdate or EventUpdateFlags Updated *EventMessageUpdate }
func (*EventMessage) UnmarshalJSON ¶
func (em *EventMessage) UnmarshalJSON(b []byte) error
type EventMessageUpdate ¶
type EventMessageUpdate struct { Unread *int Type *MessageType Time Timestamp IsReplied *int IsRepliedAll *int IsForwarded *int // Only populated for EventUpdateFlags LabelIDs []string LabelIDsAdded []string LabelIDsRemoved []string }
func (*EventMessageUpdate) DiffLabelIDs ¶
func (update *EventMessageUpdate) DiffLabelIDs(current []string) (added, removed []string)
func (*EventMessageUpdate) Patch ¶
func (update *EventMessageUpdate) Patch(msg *Message)
type EventRefresh ¶
type EventRefresh int
const ( EventRefreshMail EventRefresh = 1 << iota EventRefreshContacts )
type ImportMessageResult ¶ added in v0.2.7
type ImportResult ¶ added in v0.2.7
type ImportResult map[string]ImportMessageResult
func (ImportResult) Err ¶ added in v0.2.7
func (res ImportResult) Err() error
type Importer ¶ added in v0.2.7
type Importer struct {
// contains filtered or unexported fields
}
func (*Importer) Commit ¶ added in v0.2.7
func (imp *Importer) Commit() (ImportResult, error)
type Message ¶
type Message struct { ID string `json:",omitempty"` Order int64 ConversationID string `json:",omitempty"` Subject string Unread int Type MessageType Sender *MessageAddress ToList []*MessageAddress Time Timestamp Size int64 NumAttachments int IsEncrypted MessageEncryption ExpirationTime Timestamp IsReplied int IsRepliedAll int IsForwarded int SpamScore int AddressID string Body string MIMEType string `json:",omitempty"` CCList []*MessageAddress BCCList []*MessageAddress ReplyTos []*MessageAddress Header string `json:",omitempty"` Attachments []*Attachment LabelIDs []string ExternalID string `json:",omitempty"` }
func (*Message) Read ¶
func (msg *Message) Read(keyring openpgp.KeyRing, prompt openpgp.PromptFunction) (*openpgp.MessageDetails, error)
type MessageAction ¶
type MessageAction int
const ( MessageReply MessageAction = iota MessageReplyAll MessageForward )
type MessageAddress ¶
type MessageCount ¶
type MessageEncryption ¶
type MessageEncryption int
const ( MessageUnencrypted MessageEncryption = iota MessageEncryptedInternal MessageEncryptedExternal MessageEncryptedOutside MessageEncryptedInlinePGP MessageEncryptedPGPMIME )
type MessageFilter ¶
type MessageKeyPacket ¶
type MessagePackage ¶
type MessagePackageSet ¶
type MessagePackageSet struct { Type MessagePackageType // OR of each Type Addresses map[string]*MessagePackage MIMEType string Body string // Encrypted body data packet // Only if cleartext is sent BodyKey *PackedKey `json:",omitempty"` AttachmentKeys map[string]*PackedKey `json:",omitempty"` // contains filtered or unexported fields }
func NewMessagePackageSet ¶
func NewMessagePackageSet(attachmentKeys map[string]*packet.EncryptedKey) *MessagePackageSet
func (*MessagePackageSet) AddCleartext ¶
func (set *MessagePackageSet) AddCleartext(addr string) (*MessagePackage, error)
func (*MessagePackageSet) AddInternal ¶
func (set *MessagePackageSet) AddInternal(addr string, pub *openpgp.Entity) (*MessagePackage, error)
func (*MessagePackageSet) Encrypt ¶
func (set *MessagePackageSet) Encrypt(mimeType string, signed *openpgp.Entity) (io.WriteCloser, error)
Encrypt encrypts the data that will be written to the returned io.WriteCloser, and optionally signs it.
type MessagePackageType ¶
type MessagePackageType int
type MessageType ¶
type MessageType int
const ( MessageInbox MessageType = iota MessageDraft MessageSent MessageInboxAndSent )
type OutgoingMessage ¶
type OutgoingMessage struct { ID string // Only if message expires ExpirationTime int // Duration in seconds Packages []*MessagePackageSet }
type PrivateKey ¶
type PrivateKeyFlags ¶
type PrivateKeyFlags int
const ( PrivateKeyVerify PrivateKeyFlags = 1 PrivateKeyEncrypt PrivateKeyFlags = 2 )
type PublicKeyResp ¶
type PublicKeyResp struct { RecipientType RecipientType MIMEType string Keys []*PublicKey }
type RawAPIError ¶
type RawAPIError struct {
Message string `json:"Error"`
}
type RecipientType ¶
type RecipientType int
const ( RecipientInternal RecipientType = 1 RecipientExternal = 2 )