protonmail

package
v0.2.10-0...-e52ecc5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package protonmail implements a ProtonMail API client.

Index

Constants

View Source
const (
	LabelInbox    = "0"
	LabelAllDraft = "1"
	LabelAllSent  = "2"
	LabelTrash    = "3"
	LabelSpam     = "4"
	LabelAllMail  = "5"
	LabelArchive  = "6"
	LabelSent     = "7"
	LabelDraft    = "8"
	LabelStarred  = "10"
)
View Source
const (
	MessagePackageInternal         MessagePackageType = 1
	MessagePackageEncryptedOutside                    = 2
	MessagePackageCleartext                           = 4
	MessagePackageInlinePGP                           = 8
	MessagePackagePGPMIME                             = 16
	MessagePackageMIME                                = 32
)
View Source
const Version = 3

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    int
	Message string
}

func (*APIError) Error

func (err *APIError) Error() string

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 AttachmentKey struct {
	ID   string
	Key  string
	Algo string
}

type Auth

type Auth struct {
	ExpiresAt    time.Time
	Scope        string
	UID          string
	AccessToken  string
	RefreshToken string
	EventID      string
	PasswordMode PasswordMode
}

type AuthInfo

type AuthInfo struct {
	TwoFactor     int
	TwoFactorInfo struct {
		Enabled int
		U2F     interface{} // TODO
		TOTP    int
	} `json:"2FA"`
	// contains filtered or unexported fields
}

type AuthInfoResp

type AuthInfoResp struct {
	AuthInfo
	Version         int
	Modulus         string
	ServerEphemeral string
	Salt            string
	SRPSession      string
	// contains filtered or unexported fields
}

func (*AuthInfoResp) Err

func (r *AuthInfoResp) Err() error

type Client

type Client struct {
	RootURL    string
	AppVersion string

	HTTPClient *http.Client
	ReAuth     func() error
	// contains filtered or unexported fields
}

Client is a ProtonMail API client.

func (*Client) Auth

func (c *Client) Auth(username, password, twoFactorCode string, info *AuthInfo) (*Auth, error)

func (*Client) AuthInfo

func (c *Client) AuthInfo(username string) (*AuthInfo, error)

func (*Client) AuthRefresh

func (c *Client) AuthRefresh(expiredAuth *Auth) (*Auth, error)

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

func (c *Client) CreateDraftMessage(msg *Message, parentID string) (*Message, error)

CreateDraftMessage creates a new draft message. ToList, CCList, BCCList, Subject, Body and AddressID are required in msg.

func (*Client) DeleteAllContacts

func (c *Client) DeleteAllContacts() error

func (*Client) DeleteContacts

func (c *Client) DeleteContacts(ids []string) ([]*DeleteContactResp, error)

func (*Client) DeleteMessages

func (c *Client) DeleteMessages(ids []string) error

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) GetContact

func (c *Client) GetContact(id string) (*Contact, error)

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() (*User, error)

func (*Client) GetEvent

func (c *Client) GetEvent(last string) (*Event, error)

func (*Client) GetMessage

func (c *Client) GetMessage(id string) (*Message, error)

func (*Client) GetPublicKeys

func (c *Client) GetPublicKeys(email string) (*PublicKeyResp, error)

GetPublicKeys retrieves public keys for a user.

func (*Client) Import

func (c *Client) Import(metadata map[string]*Message) (*Importer, error)

func (*Client) LabelMessages

func (c *Client) LabelMessages(labelID string, ids []string) error

func (*Client) ListAddresses

func (c *Client) ListAddresses() ([]*Address, error)

func (*Client) ListContacts

func (c *Client) ListContacts(page, pageSize int) (total int, contacts []*Contact, err error)

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

func (c *Client) ListKeySalts() (map[string][]byte, error)

func (*Client) ListMessages

func (c *Client) ListMessages(filter *MessageFilter) (total int, messages []*Message, err error)

func (*Client) Logout

func (c *Client) Logout() error

func (*Client) MarkMessagesRead

func (c *Client) MarkMessagesRead(ids []string) error

func (*Client) MarkMessagesUnread

func (c *Client) MarkMessagesUnread(ids []string) error

func (*Client) SendMessage

func (c *Client) SendMessage(msg *OutgoingMessage) (sent, parent *Message, err error)

func (*Client) UndeleteMessages

func (c *Client) UndeleteMessages(ids []string) error

func (*Client) UnlabelMessages

func (c *Client) UnlabelMessages(labelID string, ids []string) error

func (*Client) Unlock

func (c *Client) Unlock(auth *Auth, keySalts map[string][]byte, passphrase string) (openpgp.EntityList, error)

func (*Client) UpdateContact

func (c *Client) UpdateContact(id string, contact *ContactImport) (*Contact, error)

func (*Client) UpdateDraftMessage

func (c *Client) UpdateDraftMessage(msg *Message) (*Message, error)

type Contact

type Contact struct {
	ID         string
	Name       string
	UID        string
	Size       int
	CreateTime int64
	ModifyTime int64
	LabelIDs   []string

	// Not when using ListContacts
	ContactEmails []*ContactEmail
	Cards         []*ContactCard
}

type ContactCard

type ContactCard struct {
	Type      ContactCardType
	Data      string
	Signature string
}

func NewEncryptedContactCard

func NewEncryptedContactCard(r io.Reader, to []*openpgp.Entity, signer *openpgp.Entity) (*ContactCard, error)

func NewSignedContactCard

func NewSignedContactCard(r io.Reader, signer *openpgp.Entity) (*ContactCard, error)

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 ContactEmail struct {
	ID        string
	Email     string
	Type      []string
	Defaults  ContactEmailDefaults
	Order     int
	ContactID string
	LabelIDs  []string

	// Only when using ListContactsEmails
	Name string
}

type ContactEmailDefaults

type ContactEmailDefaults int

type ContactExport

type ContactExport struct {
	ID    string
	Cards []*ContactCard
}

type ContactImport

type ContactImport struct {
	Cards []*ContactCard
}

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         int64
	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

type ImportMessageResult struct {
	Err       error
	MessageID string
}

type ImportResult

type ImportResult map[string]ImportMessageResult

func (ImportResult) Err

func (res ImportResult) Err() error

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

func (*Importer) Commit

func (imp *Importer) Commit() (ImportResult, error)

func (*Importer) ImportMessage

func (imp *Importer) ImportMessage(key string) (io.Writer, error)

type Message

type Message struct {
	ID             string
	Order          int64
	Subject        string
	Unread         int
	Type           MessageType
	Sender         *MessageAddress
	ReplyTo        *MessageAddress
	ToList         []*MessageAddress
	Time           int64
	Size           int64
	NumAttachments int
	IsEncrypted    MessageEncryption
	ExpirationTime int64
	IsReplied      int
	IsRepliedAll   int
	IsForwarded    int
	SpamScore      int
	AddressID      string
	Body           string
	MIMEType       string `json:",omitempty"`
	CCList         []*MessageAddress
	BCCList        []*MessageAddress
	Header         string
	Attachments    []*Attachment
	LabelIDs       []string
	ExternalID     string
}

func (*Message) Encrypt

func (msg *Message) Encrypt(to []*openpgp.Entity, signed *openpgp.Entity) (plaintext io.WriteCloser, err error)

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 MessageAddress struct {
	Address string
	Name    string
}

type MessageBodyKey

type MessageBodyKey struct {
	Algorithm string
	Key       string
}

type MessageCount

type MessageCount struct {
	LabelID string
	Total   int
	Unread  int
}

type MessageEncryption

type MessageEncryption int
const (
	MessageUnencrypted MessageEncryption = iota
	MessageEncryptedInternal
	MessageEncryptedExternal
	MessageEncryptedOutside

	MessageEncryptedInlinePGP
	MessageEncryptedPGPMIME
)

type MessageFilter

type MessageFilter struct {
	Page     int
	PageSize int
	Limit    int

	Label        string
	Sort         string
	Asc          bool
	Begin        int64
	End          int64
	Keyword      string
	To           string
	From         string
	Subject      string
	Attachments  *bool
	Starred      *bool
	Unread       *bool
	Conversation string
	AddressID    string
	ID           []string
	ExternalID   string
}

type MessageKeyPacket

type MessageKeyPacket struct {
	ID         string
	KeyPackets string
}

type MessagePackage

type MessagePackage struct {
	Type MessagePackageType

	BodyKeyPacket        string
	AttachmentKeyPackets map[string]string
	Signature            int

	// Only if encrypted for outside
	PasswordHint string
	Auth         interface{} // TODO
	Token        string
	EncToken     string
}

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        *MessageBodyKey `json:",omitempty"`
	AttachmentKeys map[string]string
	// 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 PasswordMode

type PasswordMode int
const (
	PasswordSingle PasswordMode = 1
	PasswordTwo                 = 2
)

type PrivateKey

type PrivateKey struct {
	ID          string
	Version     int
	Flags       PrivateKeyFlags
	PrivateKey  string
	Fingerprint string
	Activation  interface{} // TODO
	Primary     int
}

func (*PrivateKey) Entity

func (priv *PrivateKey) Entity() (*openpgp.Entity, error)

type PrivateKeyFlags

type PrivateKeyFlags int
const (
	PrivateKeyVerify  PrivateKeyFlags = 1
	PrivateKeyEncrypt PrivateKeyFlags = 2
)

type PublicKey

type PublicKey struct {
	Send      int
	PublicKey string
}

func (*PublicKey) Entity

func (pub *PublicKey) Entity() (*openpgp.Entity, error)

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
)

type User

type User struct {
	ID         string
	Name       string
	UsedSpace  int
	Currency   string // e.g. EUR
	Credit     int
	MaxSpace   int
	MaxUpload  int
	Role       int // TODO
	Private    int
	Subscribed int // TODO
	Services   int // TODO
	Delinquent int
	Keys       []*PrivateKey
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL