本文整理匯總了Golang中code/google/com/p/go-imap/go1/imap.Client.UIDFetch方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.UIDFetch方法的具體用法?Golang Client.UIDFetch怎麽用?Golang Client.UIDFetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go-imap/go1/imap.Client
的用法示例。
在下文中一共展示了Client.UIDFetch方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchMessages
func FetchMessages(c *imap.Client, uidSet *imap.SeqSet) (fetched []MsgData, err error) {
cmd, errF := c.UIDFetch(uidSet, "RFC822")
if errF != nil {
err = errF
return
}
for cmd.InProgress() {
errC := c.Recv(-1)
if errC != nil {
return
}
for _, rsp := range cmd.Data {
uid := imap.AsNumber(rsp.MessageInfo().Attrs["UID"])
mime := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822"])
msg, errR := mail.ReadMessage(bytes.NewReader(mime))
if errR != nil {
continue
}
if msg != nil {
msgdata := GetMessage(msg, uid)
fetched = append(fetched, msgdata)
}
}
cmd.Data = nil
}
return
}
示例2: FetchAllUIDs
func FetchAllUIDs(c *imap.Client) (uids []uint32, err error) {
maxmessages := 150000
uids = make([]uint32, maxmessages)
set, errS := imap.NewSeqSet("1:*")
if errS != nil {
err = errS
return
}
cmd, errF := c.UIDFetch(set, "RFC822.SIZE")
if errF != nil {
err = errF
return
}
messagenum := uint32(0)
for cmd.InProgress() {
errC := c.Recv(-1)
if errC != nil {
continue
}
for _, rsp := range cmd.Data {
uid := imap.AsNumber(rsp.MessageInfo().Attrs["UID"])
uids[messagenum] = uid
}
cmd.Data = nil
messagenum++
}
uids = uids[:messagenum]
return
}
示例3: getEmails
// getEmails will fetch the full bodies of all emails listed in the given command.
func getEmails(client *imap.Client, cmd *imap.Command) ([]map[string]interface{}, error) {
var emails []map[string]interface{}
seq := new(imap.SeqSet)
for _, rsp := range cmd.Data {
for _, uid := range rsp.SearchResults() {
seq.AddNum(uid)
}
}
if seq.Empty() {
return emails, nil
}
fCmd, err := imap.Wait(client.UIDFetch(seq, "INTERNALDATE", "BODY[]", "UID", "RFC822.HEADER"))
if err != nil {
return emails, err
}
var email map[string]interface{}
for _, msgData := range fCmd.Data {
msgFields := msgData.MessageInfo().Attrs
email, err = newEmailMessage(msgFields)
if err != nil {
return emails, err
}
emails = append(emails, email)
// mark message as read
fSeq := new(imap.SeqSet)
fSeq.AddNum(imap.AsNumber(msgFields["UID"]))
_, err = imap.Wait(client.UIDStore(fSeq, "+FLAGS", "\\SEEN"))
if err != nil {
return emails, err
}
}
return emails, nil
}
示例4: FetchMessages
func FetchMessages(c *imap.Client, uidSet *imap.SeqSet) (err error) {
cmd, err := c.UIDFetch(uidSet, "RFC822")
for cmd.InProgress() {
c.Recv(-1)
for _, rsp := range cmd.Data {
uid := imap.AsNumber(rsp.MessageInfo().Attrs["UID"])
mime := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822"])
if msg, _ := mail.ReadMessage(bytes.NewReader(mime)); msg != nil {
PrintMessageAsJSON(msg, uid)
}
}
cmd.Data = nil
}
return
}
示例5: FetchMessage
func FetchMessage(conn *imap.Client, messageUID uint32) (msg MessageData, err error) {
seq, _ := imap.NewSeqSet("")
seq.AddNum(messageUID)
var cmd *imap.Command
cmd, err = imap.Wait(conn.UIDFetch(seq, "INTERNALDATE", "BODY[]", "UID", "RFC822.HEADER"))
if err != nil {
log.Printf("Unable to fetch message (%d): %s", messageUID, err.Error())
return
}
if len(cmd.Data) == 0 {
log.Printf("Unable to fetch message (%d) from src: NO DATA", messageUID)
return msg, NotFound
}
msgFields := cmd.Data[0].MessageInfo().Attrs
msg = MessageData{InternalDate: imap.AsDateTime(msgFields["INTERNALDATE"]), Body: imap.AsBytes(msgFields["BODY[]"])}
return msg, nil
}
示例6: GetMessage
func GetMessage(folder, uid string, client *imap.Client) (messag *Message, e error) {
cmd, err := client.Select(folder, true)
if err != nil {
return nil, err
}
uidlist, _ := imap.NewSeqSet(uid)
//uidlist.Add(uid)
fmt.Println("get_mess", folder, uid)
mess := new(Message)
mess.Folder = folder
cmd, err = imap.Wait(client.UIDFetch(uidlist, "FLAGS", "INTERNALDATE", "RFC822.SIZE", "RFC822")) // "RFC822.HEADER", "BODY.PEEK[TEXT]") )
if err != nil {
return mess, err
}
fmt.Println(len(cmd.Data), cmd.Data)
rsp := cmd.Data[0]
minfo := rsp.MessageInfo()
mess.Uid = minfo.UID
msg, _ := mail.ReadMessage(bytes.NewReader(imap.AsBytes(minfo.Attrs["RFC822"])))
mime, mime_err := enmime.ParseMIMEBody(msg)
for flag, boo := range minfo.Flags {
if flag == "\\Seen" && boo {
mess.Seen = true
}
if flag == "\\Flagged" && boo {
mess.Flagged = true
}
}
/*
bites := imap.AsBytes(minfo.Attrs["RFC822"])
msg, msg_err := mail.ReadMessage(bytes.NewReader(bites))
if msg_err != nil {
return mess, msg_err
}
*/
//fmt.Println(msg.Header.Get("Content-type"))
//fmt.Println(msg.Header.Get("To"))
//fmt.Println(msg.Header.Get("Delivered-To"))
// From
from, fro_err := mail.ParseAddress(msg.Header.Get("From"))
if fro_err != nil {
fmt.Println("address ettot")
} else {
mess.FromName = from.Name
mess.FromEmail = from.Address
}
//for i, m := range minfo.Attrs {
//fmt.Println(i,m)
//}
// Date
dat := imap.AsDateTime(minfo.Attrs["INTERNALDATE"])
mess.Date = dat.Format("2006-01-02 15:04:05")
mess.Subject = msg.Header.Get("Subject")
mess.ContentType = msg.Header.Get("Content-Type")
//fmt.Println("body=", cmd.Data[0].String)
//bodyb := imap.AsBytes(minfo.Attrs["BODY[TEXT]"])
//bb := bytes.NewReader(bytes.NewReader(header + bodyb))
//fmt.Println("bodyb=", string(msg.Body))
//fmt.Printf("----\n%v\n", mime.Html == nil)
//mess.Body = mime.Text
if mime_err != nil {
fmt.Println("err=", mime_err, mime)
}
//*/
//fmt.Println("body=", body)
mess.BodyText = mime.Text
mess.BodyHtml = mime.Html //imap.AsString(minfo.Attrs["RFC822"])
return mess, nil
}