gmail

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 20 Imported by: 0

README

// IMAP supported, POP3 NOT supported, for now.

// 每封邮件有两个Index:SeqNum和Uid // SeqNum是永远连续的,无论用户是否删除了邮件 // Uid则是唯一不变的

Documentation

Index

Constants

View Source
const (
	INBOX      = "INBOX"
	StartIndex = 1 // First index(Uid or SeqNum) is 1, NOT 0
)

Variables

View Source
var (
	InProviders = []Provider{
		{
			SMTPAddress: "smtp.gmail.com:465",
			SMTPIsSSL:   true,
			POP3Address: "pop.gmail.com:995",
			POP3IsSSL:   true,
			IMAPAddress: "imap.gmail.com:993",
			IMAPIsSSL:   true,
			EmailDomain: "gmail.com",
		},
		{
			SMTPAddress: "smtp.qq.com:465",
			SMTPIsSSL:   true,
			POP3Address: "pop.qq.com:995",
			POP3IsSSL:   true,
			IMAPAddress: "imap.qq.com:993",
			IMAPIsSSL:   true,
			EmailDomain: "qq.com",
		},
		{
			SMTPAddress: "smtp.mail.yahoo.com:465",
			SMTPIsSSL:   true,
			POP3Address: "pop.mail.yahoo.com:110",
			POP3IsSSL:   true,
			IMAPAddress: "imap.mail.yahoo.com:993",
			IMAPIsSSL:   true,
			EmailDomain: "yahoo.com",
		},
		{
			SMTPAddress: "smtp.aliyun.com:25",
			SMTPIsSSL:   false,
			POP3Address: "pop3.aliyun.com:110",
			POP3IsSSL:   false,
			IMAPAddress: "imap.aliyun.com",
			IMAPIsSSL:   false,
			EmailDomain: "aliyun.com",
		},
		{
			SMTPAddress: "smtp.163.com:465",
			SMTPIsSSL:   true,
			POP3Address: "pop.163.com:995",
			POP3IsSSL:   true,
			IMAPAddress: "imap.163.com:993",
			IMAPIsSSL:   true,
			EmailDomain: "163.com",
		},
		{
			SMTPAddress: "smtp.126.com:465",
			SMTPIsSSL:   true,
			POP3Address: "pop.126.com:995",
			POP3IsSSL:   true,
			IMAPAddress: "imap.126.com:993",
			IMAPIsSSL:   true,
			EmailDomain: "126.com",
		},
	}
)

Functions

func GetHost

func GetHost(email string) (string, error)

func GetLoginName

func GetLoginName(email string) (string, error)

func MakeBody

func MakeBody() (string, error)

func MimeConvHtml

func MimeConvHtml()

func Send

func Send(e Envelope, c SendContent, password string, p *Provider) error

Provider can be null, if null, will try to parse built-in provider by From email address.

func TestAccount

func TestAccount(addr, pwd string, p *Provider) error

send to itself to test it

func Validate

func Validate(email string) error

Types

type Account

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

func NewAccount

func NewAccount(email, showname, password string) (*Account, error)

func (*Account) Email

func (a *Account) Email() string

func (*Account) Password

func (a *Account) Password() string

func (*Account) ShowName

func (a *Account) ShowName() string

func (*Account) UserName

func (a *Account) UserName() string

type AddrEdit

type AddrEdit struct {
	Email    string
	Showname string
}

专用于Envelope中用户填写方便而准备的结构体

func (*AddrEdit) Domain

func (ae *AddrEdit) Domain() (string, error)

func (*AddrEdit) LoginName

func (ae *AddrEdit) LoginName() (string, error)

func (*AddrEdit) Validate

func (ae *AddrEdit) Validate() error

type Address

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

func NewAddress

func NewAddress(email, showname string) (*Address, error)

func (*Address) Email

func (a *Address) Email() string

func (*Address) EmailReplaceLoginNameTail

func (a *Address) EmailReplaceLoginNameTail(replace string) string

func (*Address) Host

func (a *Address) Host() string

func (*Address) ShowName

func (a *Address) ShowName() string

func (*Address) UserName

func (a *Address) UserName() string

in quant.lol, login name is username@quant.lol, not username only

type Attachment

type Attachment struct {
	FileName string
	Content  []byte
}

type BodyType

type BodyType int
const (
	BodyTypePlainText BodyType = iota + 0
	BodyTypeHTML
)

type Envelope

type Envelope struct {
	Datetime time.Time
	Subject  string
	From     AddrEdit
	To       []AddrEdit
	Cc       []AddrEdit
	// contains filtered or unexported fields
}

func (*Envelope) Uid

func (e *Envelope) Uid() int

func (*Envelope) Validate

func (e *Envelope) Validate() error

type Filter

type Filter struct {
	AfterThisTime  *time.Time
	BeforeThisTime *time.Time

	SubjectContains *string
	SenderContains  *string

	IndexType  IndexType
	IndexStart *int
	IndexStop  *int
}

func (*Filter) CheckEnvelope

func (f *Filter) CheckEnvelope(env *Envelope) bool

Check whether input envelope fits current Filter

func (*Filter) Useful

func (f *Filter) Useful() bool

type IndexType

type IndexType int
const (
	IndexTypeUndefined IndexType = iota + 0
	IndexTypeUid
	IndexTypeSeqNum
)

type MQ

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

func NewConn

func NewConn(as []Account) (*MQ, error)

func (*MQ) Close

func (m *MQ) Close() error

func (*MQ) Pub

func (m *MQ) Pub(subject string, data []byte)

type Mail

type Mail struct {
	Env     Envelope
	Content RecvContent
}

func Recv

func Recv(email, password string, p *Provider, filter *Filter) ([]Mail, error)

type Msg

type Msg struct {
	Subject string
	Body    []byte
}

type Provider

type Provider struct {
	SMTPAddress string
	SMTPIsSSL   bool
	POP3Address string
	POP3IsSSL   bool
	IMAPAddress string
	IMAPIsSSL   bool
	EmailDomain string // Used to parse provider from email address
}

Mail service provider

func TryParseProvider

func TryParseProvider(email string) (*Provider, error)

func (*Provider) GetReceiveServer

func (p *Provider) GetReceiveServer() (address string, port int, ssl bool, err error)

Get receive server: IMAP / POP3

func (*Provider) GetSendServer

func (p *Provider) GetSendServer() (address string, port int, ssl bool, err error)

Get send server: SMTP / IMAP

func (Provider) String

func (p Provider) String() string

func (*Provider) Validate

func (p *Provider) Validate() error

type Receiver

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

func NewReceiver

func NewReceiver(email, password string, p *Provider) (*Receiver, error)

IMAP supported, POP3 NOT supported.

  • p: 可以为空,也可以是指定的provider,可选参数

func (*Receiver) Close

func (s *Receiver) Close() error

func (*Receiver) GetBoxInfo

func (s *Receiver) GetBoxInfo(box string) (total, unread int, err error)

func (*Receiver) GetEnvelopes

func (s *Receiver) GetEnvelopes(box string, filter *Filter) ([]Envelope, error)

Notice: 如何尽可能少的拉取Envelope: 把起止Uid或者SeqNum作为查询条件放进去

func (*Receiver) GetMails

func (s *Receiver) GetMails(box string, uid []int) ([]Mail, error)

Get mails by Uid set

func (*Receiver) ShowAllBoxes

func (s *Receiver) ShowAllBoxes() ([]string, error)

type RecvContent

type RecvContent struct {
	BodyType    BodyType
	BodyString  string
	Attachments []Attachment
}

type SendContent

type SendContent struct {
	BodyType        BodyType
	BodyString      string
	AttachmentsPath []string
}

type Template

type Template struct {
	Signature string
}

Jump to

Keyboard shortcuts

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