MCPcopy Create free account
hub / github.com/openclaw/gogcli / FetchMessages

Method FetchMessages

internal/cmd/gmail_watch_source.go:70–123  ·  view source on GitHub ↗
(ctx context.Context, ids []string)

Source from the content-addressed store, hash-verified

68}
69
70func (s *gmailWatchSource) FetchMessages(ctx context.Context, ids []string) (gmailwatch.MessageBatch, error) {
71 batch := gmailwatch.MessageBatch{
72 Messages: make([]gmailwatch.Message, 0, len(ids)),
73 }
74 format := gmailWatchFormatMetadata
75 if s.includeBody {
76 format = gmailFormatFull
77 }
78
79 for _, id := range ids {
80 if strings.TrimSpace(id) == "" {
81 continue
82 }
83 message, err := s.service.Users.Messages.Get("me", id).
84 Format(format).
85 MetadataHeaders(gmailBasicMetadataHeaders...).
86 Context(ctx).
87 Do()
88 if err != nil {
89 if isNotFoundAPIError(err) {
90 continue
91 }
92 return gmailwatch.MessageBatch{}, err
93 }
94 if message == nil {
95 continue
96 }
97 if labelSetContains(s.excludeLabelIDs, message.LabelIds) {
98 batch.Excluded++
99 if s.verbose && s.logf != nil {
100 s.logf("watch: excluded message %s labels=%v", message.Id, message.LabelIds)
101 }
102 continue
103 }
104
105 item := gmailwatch.Message{
106 ID: message.Id,
107 ThreadID: message.ThreadId,
108 From: headerValue(message.Payload, "From"),
109 To: headerValue(message.Payload, "To"),
110 Subject: headerValue(message.Payload, "Subject"),
111 Date: formatGmailDateInLocation(headerValue(message.Payload, "Date"), s.dateLocation),
112 Snippet: message.Snippet,
113 Labels: message.LabelIds,
114 }
115 if s.includeBody {
116 body := gmailcontent.BestBodyText(message.Payload)
117 item.Body, item.BodyTruncated = truncateUTF8Bytes(body, s.maxBodyBytes)
118 }
119 batch.Messages = append(batch.Messages, item)
120 }
121
122 return batch, nil
123}
124
125func historyPageFromGmail(response *gmail.ListHistoryResponse) gmailwatch.HistoryPage {
126 if response == nil {

Callers

nothing calls this directly

Calls 9

BestBodyTextFunction · 0.92
isNotFoundAPIErrorFunction · 0.85
labelSetContainsFunction · 0.85
truncateUTF8BytesFunction · 0.85
logfMethod · 0.80
headerValueFunction · 0.70
DoMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected