cmdg

package
v0.0.0-...-1c2fe5b Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: GPL-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Inbox   = "INBOX"
	Trash   = "TRASH"
	Unread  = "UNREAD"
	Starred = "STARRED"
)

Special labels.

Variables

View Source
var (
	// GPG is the handle to a GPG config.
	GPG *gpg.GPG

	// Lynx is the executable to use as web browser to use to render HTML to text.
	Lynx = "lynx"

	// Openssl is the executable is used to verify some signatures.
	Openssl = "openssl"

	// ErrMissing is used e.g. if a header is not present. As opposed to malformed.
	ErrMissing = fmt.Errorf("resource missing")
)

Functions

func Configure

func Configure(fn string) error

Configure sets up configuration with oauth and stuff.

func MIMEDecode

func MIMEDecode(s string) (string, error)

MIMEDecode does mime encode for fmail. Seems to be a special version of base64.

func MIMEEncode

func MIMEEncode(s string) string

MIMEEncode does mime decode for gmail. Seems to be special version of base64.

Types

type Attachment

type Attachment struct {
	ID    string
	MsgID string

	Part *gmail.MessagePart
	// contains filtered or unexported fields
}

Attachment is an attachment.

func (*Attachment) Download

func (a *Attachment) Download(ctx context.Context) ([]byte, error)

Download downloads an attachment.

type CmdG

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

CmdG is the main app for cmdg. It holds both rpc clients and various caches. Everything except the UI.

func New

func New(fn string) (*CmdG, error)

New creates a new CmdG.

func NewFake

func NewFake(client *http.Client) (*CmdG, error)

NewFake creates a fake client, used for testing.

func (*CmdG) BatchArchive

func (c *CmdG) BatchArchive(ctx context.Context, ids []string) error

BatchArchive archives all the given message IDs.

func (*CmdG) BatchDelete

func (c *CmdG) BatchDelete(ctx context.Context, ids []string) error

BatchDelete deletes. Does not put in trash. Does not pass go: "Immediately and permanently deletes the specified message. This operation cannot be undone."

cmdg doesn't actually request oauth permission to do this, so this function is never used. Instead BatchTrash is used.

func (*CmdG) BatchLabel

func (c *CmdG) BatchLabel(ctx context.Context, ids []string, labelID string) error

BatchLabel adds one new label to many messages.

func (*CmdG) BatchTrash

func (c *CmdG) BatchTrash(ctx context.Context, ids []string) error

BatchTrash trashes the messages.

There isn't actually a BatchTrash, so we'll pretend with just labels.

func (*CmdG) BatchUnlabel

func (c *CmdG) BatchUnlabel(ctx context.Context, ids []string, labelID string) (err error)

BatchUnlabel removes one label from many messages.

func (*CmdG) Contacts

func (c *CmdG) Contacts() []string

Contacts returns a list of all contacts.

func (*CmdG) GetContacts

func (c *CmdG) GetContacts(ctx context.Context) ([]string, error)

GetContacts gets all contact's email addresses in "Name Name <email@example.com>" format.

func (*CmdG) GetFile

func (c *CmdG) GetFile(ctx context.Context, fn string) ([]byte, error)

GetFile downloads a file from the config folder.

func (*CmdG) GetProfile

func (c *CmdG) GetProfile(ctx context.Context) (*gmail.Profile, error)

GetProfile returns the profile for the current user.

func (*CmdG) History

func (c *CmdG) History(ctx context.Context, startID HistoryID, labelID string) ([]*gmail.History, HistoryID, error)

History returns history since startID (all pages).

func (*CmdG) HistoryID

func (c *CmdG) HistoryID(ctx context.Context) (HistoryID, error)

HistoryID returns the current history ID.

func (*CmdG) LabelCache

func (c *CmdG) LabelCache(label *Label) *Label

LabelCache returns the label fro the cache, or nil if not found.

func (*CmdG) Labels

func (c *CmdG) Labels() []*Label

Labels returns a list of all labels.

func (*CmdG) ListDrafts

func (c *CmdG) ListDrafts(ctx context.Context) ([]*Draft, error)

ListDrafts lists all drafts.

func (*CmdG) ListMessages

func (c *CmdG) ListMessages(ctx context.Context, label, query, token string) (*Page, error)

ListMessages lists messages in a given label or query, with optional page token.

func (*CmdG) LoadContacts

func (c *CmdG) LoadContacts(ctx context.Context) error

LoadContacts reads all contacts from the cloud.

func (*CmdG) LoadLabels

func (c *CmdG) LoadLabels(ctx context.Context) error

LoadLabels batch loads all labels into the cache.

func (*CmdG) MakeDraft

func (c *CmdG) MakeDraft(ctx context.Context, msg string) error

MakeDraft creates a new draft.

func (*CmdG) MessageCache

func (c *CmdG) MessageCache(msg *Message) *Message

MessageCache returns the message from the cache, or nil if not found.

func (*CmdG) MoreHistory

func (c *CmdG) MoreHistory(ctx context.Context, start HistoryID, labelID string) (bool, error)

MoreHistory returns if stuff happened since start ID.

func (*CmdG) PutFile

func (c *CmdG) PutFile(ctx context.Context, fn string, contents []byte) error

PutFile uploads a file into the config dir on Google drive.

func (*CmdG) SendParts

func (c *CmdG) SendParts(ctx context.Context, threadID ThreadID, mp string, head mail.Header, parts []*Part) error

SendParts sends a multipart message. Args:

mp:    multipart type. "mixed" is a typical type.
head:  Email header.
parts: Email parts.

func (*CmdG) UpdateFile

func (c *CmdG) UpdateFile(ctx context.Context, fn string, contents []byte) error

UpdateFile updates an existing file on Google drive in the config folder..

type Config

type Config struct {
	OAuth ConfigOAuth
}

Config is… hmm… this should probably be cleand up.

type ConfigOAuth

type ConfigOAuth struct {
	ClientID, ClientSecret, RefreshToken, AccessToken, APIKey string
}

ConfigOAuth contains the config for the oauth.

type DataLevel

type DataLevel string

DataLevel is the level of detail to download.

const (
	LevelEmpty    DataLevel = ""         // Nothing
	LevelMinimal  DataLevel = "minimal"  // ID, labels
	LevelMetadata DataLevel = "metadata" // ID, labels, headers
	LevelFull     DataLevel = "full"     // ID, labels, headers, payload
)

Different levels of detail to download.

type Draft

type Draft struct {
	ID       string
	Response *gmail.Draft
	// contains filtered or unexported fields
}

Draft is a draft.

func NewDraft

func NewDraft(c *CmdG, id string) *Draft

NewDraft returns a new draft.

func (*Draft) Delete

func (d *Draft) Delete(ctx context.Context) error

Delete deletes the draft.

func (*Draft) GetBody

func (d *Draft) GetBody(ctx context.Context) (string, error)

GetBody returns the body.

func (*Draft) GetHeader

func (d *Draft) GetHeader(ctx context.Context, h string) (string, error)

GetHeader retrieves a header.

func (*Draft) GetSubject

func (d *Draft) GetSubject(ctx context.Context) (string, error)

GetSubject returns the draft subject.

func (*Draft) HasData

func (d *Draft) HasData(level DataLevel) bool

HasData returns if data at a given level is already loaded.

func (*Draft) Send

func (d *Draft) Send(ctx context.Context) error

Send sends the draft. Sending a draft makes it no longer a draft.

func (*Draft) UpdateParts

func (d *Draft) UpdateParts(ctx context.Context, head mail.Header, parts []*Part) error

UpdateParts updates a draft… right?

type HistoryID

type HistoryID uint64

HistoryID is a sparse timeline of numbers.

type Label

type Label struct {
	ID       string
	Label    string
	Response *gmail.Label
	// contains filtered or unexported fields
}

Label is a gmail label.

func (*Label) LabelColor

func (l *Label) LabelColor() string

LabelColor returns an ANSI escape to render this label's color.

func (*Label) LabelColorChar

func (l *Label) LabelColorChar() string

LabelColorChar returns a full string to render just one char wide label.

func (*Label) LabelString

func (l *Label) LabelString() string

LabelString is the string of the label.

type Message

type Message struct {
	ID string

	Response *gmail.Message
	// contains filtered or unexported fields
}

Message is an email message.

func NewMessage

func NewMessage(c *CmdG, msgID string) *Message

NewMessage creates a new message.

func NewMessageWithResponse

func NewMessageWithResponse(c *CmdG, msgID string, resp *gmail.Message, level DataLevel) *Message

NewMessageWithResponse creates a new message from data already received from the gmail API.

func (*Message) AddLabelID

func (msg *Message) AddLabelID(ctx context.Context, labelID string) error

AddLabelID adds a label to a message.

func (*Message) AddLabelIDLocal

func (msg *Message) AddLabelIDLocal(labelID string)

AddLabelIDLocal adds a local label to the local cache *only*. It'll be overwritten at next sync. It's used for faster UI response time on label adding.

func (*Message) Attachments

func (msg *Message) Attachments(ctx context.Context) ([]*Attachment, error)

Attachments returns a list of attachments.

func (*Message) GPGStatus

func (msg *Message) GPGStatus() *gpg.Status

GPGStatus returns an annotated GPG status.

func (*Message) GetBody

func (msg *Message) GetBody(ctx context.Context) (string, error)

GetBody returns the message body.

func (*Message) GetBodyHTML

func (msg *Message) GetBodyHTML(ctx context.Context) (string, error)

GetBodyHTML returns the message's HTML body.

func (*Message) GetDateHeader

func (msg *Message) GetDateHeader(ctx context.Context) (string, error)

GetDateHeader returns the string that the Date header is set to.

func (*Message) GetFrom

func (msg *Message) GetFrom(ctx context.Context) (string, error)

GetFrom returns email address (not name) of sender.

func (*Message) GetHeader

func (msg *Message) GetHeader(ctx context.Context, k string) (string, error)

GetHeader returns a header.

func (*Message) GetLabelColors

func (msg *Message) GetLabelColors(ctx context.Context, exclude string) (string, string, error)

GetLabelColors returns two strings: Labels with just colors, and one with the label strings in those colors.

func (*Message) GetLabels

func (msg *Message) GetLabels(ctx context.Context, withUnread bool) ([]*Label, error)

GetLabels returns all labels for the message.

func (*Message) GetLabelsString

func (msg *Message) GetLabelsString(ctx context.Context) (string, error)

GetLabelsString returns labels as a printable string. With colors, but without "UNREAD".

func (*Message) GetOriginalTime

func (msg *Message) GetOriginalTime(ctx context.Context) (time.Time, error)

GetOriginalTime returns the timestamp as claimed by the headers in its original timezone.

func (*Message) GetReferences

func (msg *Message) GetReferences(ctx context.Context) ([]string, error)

GetReferences returns a slice of references.

func (*Message) GetReplyTo

func (msg *Message) GetReplyTo(ctx context.Context) (string, error)

GetReplyTo returns the address to use for replies as the `To` line.

func (*Message) GetReplyToAll

func (msg *Message) GetReplyToAll(ctx context.Context) (string, string, error)

GetReplyToAll returns both To and CC lines for reply-all.

func (*Message) GetSubject

func (msg *Message) GetSubject(ctx context.Context) (string, error)

GetSubject returns the message subject.

func (*Message) GetTime

func (msg *Message) GetTime(ctx context.Context) (time.Time, error)

GetTime returns the message's time in the local timezone.

func (*Message) GetTimeFmt

func (msg *Message) GetTimeFmt(ctx context.Context) (string, error)

GetTimeFmt returns a `time` format string appropriate for the age of the message.

func (*Message) GetUnpatchedBody

func (msg *Message) GetUnpatchedBody(ctx context.Context) (string, error)

GetUnpatchedBody returns the raw body, before fixups.

func (*Message) HasData

func (msg *Message) HasData(level DataLevel) bool

HasData returns if the message has at least the given level.

func (*Message) HasLabel

func (msg *Message) HasLabel(labelID string) bool

HasLabel checks for a given labelID.

func (*Message) IsUnread

func (msg *Message) IsUnread() bool

IsUnread returns if the UNREAD label is set.

func (*Message) LocalLabels

func (msg *Message) LocalLabels() []string

LocalLabels returns the label IDs, whatever they are. If we have not downloaded anything then empty list is returned.

func (*Message) Preload

func (msg *Message) Preload(ctx context.Context, level DataLevel) error

Preload loads message data, unless it's already loaded.

func (*Message) Raw

func (msg *Message) Raw(ctx context.Context) (string, error)

Raw returns the raw message.

func (*Message) Reload

func (msg *Message) Reload(ctx context.Context, level DataLevel) error

Reload unconditionally reloads the message.

func (*Message) ReloadLabels

func (msg *Message) ReloadLabels(ctx context.Context) error

ReloadLabels reloads label data for the message.

func (*Message) RemoveLabelID

func (msg *Message) RemoveLabelID(ctx context.Context, labelID string) error

RemoveLabelID removes a label.

func (*Message) RemoveLabelIDLocal

func (msg *Message) RemoveLabelIDLocal(labelID string)

RemoveLabelIDLocal removes a local label from the local cache *only*. It'll be overwritten at next sync. It's used for faster UI response time on label removing.

func (*Message) ThreadID

func (msg *Message) ThreadID(ctx context.Context) (ThreadID, error)

ThreadID returns the thread ID of the message.

type Page

type Page struct {
	Label string
	Query string

	Messages []*Message
	Response *gmail.ListMessagesResponse
	// contains filtered or unexported fields
}

Page implements some pagination thingy. TODO: document better.

func (*Page) Next

func (p *Page) Next(ctx context.Context) (*Page, error)

Next return the next page.

func (*Page) PreloadSubjects

func (p *Page) PreloadSubjects(ctx context.Context) error

PreloadSubjects async loads message basic info.

type Part

type Part struct {
	Contents string
	Header   textproto.MIMEHeader
}

Part is a part of a message. Contents and header.

func ParseUserMessage

func ParseUserMessage(in string) (mail.Header, *Part, error)

ParseUserMessage parses what's in the user's editor and turns into into a Part and message headers.

func (*Part) FullString

func (p *Part) FullString() string

FullString returns the "serialized" part.

type ThreadID

type ThreadID string

ThreadID is IDs of threads.

var (
	// Version is the app version as reported in RPCs.
	Version = "unspecified"

	// NewThread is the thread ID to use for new threads.
	NewThread ThreadID
)

Jump to

Keyboard shortcuts

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