Skip to content

Commit

Permalink
Merge pull request #65 from Virtomize/issue/64
Browse files Browse the repository at this point in the history
issue #64 config option to allow/deny processing of empty messages
  • Loading branch information
c-seeger authored Jun 11, 2021
2 parents 20a0033 + ec1479c commit 6507cd5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 2 additions & 0 deletions conf/mail2most.conf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
SubjectOnly = false
# BodyOnly will post only the mail body
BodyOnly = false
# SkipEmptyMessages - only post messages with non empty email bodys
SkipEmptyMessages = false
# StripHTML will remove all HTML tags bevor sending a msg to mattermost
StripHTML = true
# ConvertToMarkdown will convert html mails to markdown for better readability in mattermost
Expand Down
1 change: 1 addition & 0 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type mattermost struct {
Broadcast []string
SubjectOnly bool
BodyOnly bool
SkipEmptyMessages bool
StripHTML bool
ConvertToMarkdown bool
HideFrom bool
Expand Down
8 changes: 0 additions & 8 deletions lib/imap.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,6 @@ func (m Mail2Most) GetMail(profile int) ([]Mail, error) {
return []Mail{}, err
}

// Skip empty messages.
if len(strings.TrimSpace(body)) < 1 && len(attachments) < 1 {
m.Info("blank message", map[string]interface{}{
"subject": msg.Envelope.Subject, "uid": msg.Uid,
})
continue
}

// Skip mailserver error notifications.
if strings.HasPrefix(msg.Envelope.Subject, "Delivery Status Notification") {
if m.Config.Profiles[profile].Filter.IgnoreMailErrorNotifications {
Expand Down
6 changes: 4 additions & 2 deletions lib/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error {
}

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

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

0 comments on commit 6507cd5

Please sign in to comment.