Skip to content

Commit 6507cd5

Browse files
authored
Merge pull request #65 from Virtomize/issue/64
issue #64 config option to allow/deny processing of empty messages
2 parents 20a0033 + ec1479c commit 6507cd5

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

conf/mail2most.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
SubjectOnly = false
6969
# BodyOnly will post only the mail body
7070
BodyOnly = false
71+
# SkipEmptyMessages - only post messages with non empty email bodys
72+
SkipEmptyMessages = false
7173
# StripHTML will remove all HTML tags bevor sending a msg to mattermost
7274
StripHTML = true
7375
# ConvertToMarkdown will convert html mails to markdown for better readability in mattermost

lib/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type mattermost struct {
5656
Broadcast []string
5757
SubjectOnly bool
5858
BodyOnly bool
59+
SkipEmptyMessages bool
5960
StripHTML bool
6061
ConvertToMarkdown bool
6162
HideFrom bool

lib/imap.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,6 @@ func (m Mail2Most) GetMail(profile int) ([]Mail, error) {
176176
return []Mail{}, err
177177
}
178178

179-
// Skip empty messages.
180-
if len(strings.TrimSpace(body)) < 1 && len(attachments) < 1 {
181-
m.Info("blank message", map[string]interface{}{
182-
"subject": msg.Envelope.Subject, "uid": msg.Uid,
183-
})
184-
continue
185-
}
186-
187179
// Skip mailserver error notifications.
188180
if strings.HasPrefix(msg.Envelope.Subject, "Delivery Status Notification") {
189181
if m.Config.Profiles[profile].Filter.IgnoreMailErrorNotifications {

lib/mattermost.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error {
8787
}
8888

8989
if len(strings.TrimSpace(body)) < 1 {
90-
m.Info("dead body found", map[string]interface{}{"function": "Mail2Most.PostMattermost"})
91-
return nil
90+
if m.Config.Profiles[profile].Mattermost.SkipEmptyMessages {
91+
m.Info("empty message body found", map[string]interface{}{"function": "Mail2Most.PostMattermost"})
92+
return nil
93+
}
9294
}
9395

9496
if m.Config.Profiles[profile].Mattermost.BodyPrefix != "" {

0 commit comments

Comments
 (0)