protonmail

package
v0.0.0-...-4f244d7 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 27 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 MaxMessagePageSize = 150

MaxMessagePageSize are enforced by the ProtonMail server for all message operations

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
	UserID       string
	EventID      string
	PasswordMode PasswordMode
	TwoFactor    struct {
		Enabled int
		U2F     interface{} // TODO
		TOTP    int
	} `json:"2FA"`
}

type AuthInfo

type AuthInfo struct {
	// 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 Calendar

type Calendar struct {
	ID          string
	Name        string
	Description string
	Color       string
	Display     int
	Flags       CalendarFlags
}

type CalendarEvent

type CalendarEvent struct {
	ID                string
	CalendarID        string
	CalendarKeyPacket string
	CreateTime        Timestamp
	LastEditTime      Timestamp
	Author            string
	Permissions       CalendarEventPermissions
	SharedKeyPacket   string
	SharedEvents      []CalendarEventCard
	CalendarEvents    interface{}
	PersonalEvent     []CalendarEventCard
}

type CalendarEventCard

type CalendarEventCard struct {
	Type      CalendarEventCardType
	Data      string
	Signature string
	MemberID  string
}

type CalendarEventCardType

type CalendarEventCardType int

type CalendarEventFilter

type CalendarEventFilter struct {
	Start, End     int64
	Timezone       string
	Page, PageSize int
}

type CalendarEventPermissions

type CalendarEventPermissions int

type CalendarFlags

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

func (c *Client) Auth(username, password 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) AuthTOTP

func (c *Client) AuthTOTP(code string) (scope string, err 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) GetConversation

func (c *Client) GetConversation(id, msgID string) (*Conversation, []*Message, 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) ListCalendarEvents

func (c *Client) ListCalendarEvents(calendarID string, filter *CalendarEventFilter) ([]*CalendarEvent, error)

func (*Client) ListCalendars

func (c *Client) ListCalendars(page, pageSize int) ([]*Calendar, 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) ListLabels

func (c *Client) ListLabels() ([]*Label, 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 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 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 Conversation

type Conversation struct {
	ID             string
	Order          int64
	Subject        string
	Senders        []*MessageAddress
	Recipients     []*MessageAddress
	NumMessages    int
	NumUnread      int
	NumAttachments int
	ExpirationTime Timestamp
	TotalSize      int64
	AddressID      string
	LabelIDs       []string
}

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

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 Label

type Label struct {
	ID        string
	Name      string
	Color     string
	Display   int
	Type      LabelType
	Exclusive int
	Notify    int
	Order     int
}

type LabelType

type LabelType int
const (
	LabelMessage LabelType = 1
	LabelContact LabelType = 2
)

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) 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 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 `json:",omitempty"`
}

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 PackedKey

type PackedKey struct {
	Algorithm string
	Key       string
}

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
	Primary     int
	Active      int
	Token       string
	Signature   string
}

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 Timestamp

type Timestamp int64

func (Timestamp) Time

func (t Timestamp) Time() time.Time

type User

type User struct {
	ID         string
	Name       string
	UsedSpace  int64
	Currency   string // e.g. EUR
	Credit     int
	MaxSpace   int64
	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