Skip to content

Commit

Permalink
added config option + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Seeger committed Jan 20, 2020
1 parent 969b3e1 commit 893f5ff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -23,6 +23,7 @@ Filter emails from mail accounts and send them to mattermost.
- Choose to post Subject and Body or Subject only
- Send to channels and/or users
- Profile management including default profiles
- Mail attachment support

Missing feature or found a bug ? Feel free to open an [issue](https://github.com/cseeger-epages/mail2most/issues) and let us know !

Expand Down
4 changes: 4 additions & 0 deletions conf/mail2most.conf
Expand Up @@ -55,6 +55,8 @@
StripHTML = true
# HideFrom allows you to hide the From Address in mattermost messages
HideFrom= false
# allow posting mail attachments into mattermost
MailAttachments = true

# The DefaultProfile.Filter defines a default filter
# if your Profile has no defined filter this information will be used
Expand Down Expand Up @@ -108,6 +110,8 @@
StripHTML = true
# HideFrom allows you to hide the From Address in mattermost messages
HideFrom= false
# allow posting mail attachments into mattermost
MailAttachments = true

#[Profile.Filter] contains all filters that are applied to your mails and overwrites the default
[Profile.Filter]
Expand Down
1 change: 1 addition & 0 deletions lib/config.go
Expand Up @@ -51,6 +51,7 @@ type mattermost struct {
SubjectOnly bool
StripHTML bool
HideFrom bool
MailAttachments bool
}

func parseConfig(fileName string, conf *config) error {
Expand Down
36 changes: 20 additions & 16 deletions lib/mattermost.go
Expand Up @@ -109,15 +109,17 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error {
}

var fileIDs []string
for _, a := range mail.Attachments {
fileResp, resp := c.UploadFile(a.Content, ch.Id, a.Filename)
if resp.Error != nil {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error})
} else {
if len(fileResp.FileInfos) != 1 {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error, "fileinfos": fileResp.FileInfos})
if m.Config.Profiles[profile].Mattermost.MailAttachments {
for _, a := range mail.Attachments {
fileResp, resp := c.UploadFile(a.Content, ch.Id, a.Filename)
if resp.Error != nil {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error})
} else {
fileIDs = append(fileIDs, fileResp.FileInfos[0].Id)
if len(fileResp.FileInfos) != 1 {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error, "fileinfos": fileResp.FileInfos})
} else {
fileIDs = append(fileIDs, fileResp.FileInfos[0].Id)
}
}
}
}
Expand Down Expand Up @@ -183,15 +185,17 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error {
}

var fileIDs []string
for _, a := range mail.Attachments {
fileResp, resp := c.UploadFile(a.Content, ch.Id, a.Filename)
if resp.Error != nil {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error})
} else {
if len(fileResp.FileInfos) != 1 {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error, "fileinfos": fileResp.FileInfos})
if m.Config.Profiles[profile].Mattermost.MailAttachments {
for _, a := range mail.Attachments {
fileResp, resp := c.UploadFile(a.Content, ch.Id, a.Filename)
if resp.Error != nil {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error})
} else {
fileIDs = append(fileIDs, fileResp.FileInfos[0].Id)
if len(fileResp.FileInfos) != 1 {
m.Error("Mattermost Upload File Error", map[string]interface{}{"error": resp.Error, "fileinfos": fileResp.FileInfos})
} else {
fileIDs = append(fileIDs, fileResp.FileInfos[0].Id)
}
}
}
}
Expand Down

0 comments on commit 893f5ff

Please sign in to comment.