-
Notifications
You must be signed in to change notification settings - Fork 22
check if user to send message to is empty #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,17 +82,19 @@ func (m Mail2Most) Run() error { | |
if send { | ||
err := m.PostMattermost(p, mail) | ||
if err != nil { | ||
m.Error("Mattermost Error", map[string]interface{}{ | ||
m.Error("Right after PostMattermost, Mattermost Error. Email not set as synced in mattermost.", map[string]interface{}{ | ||
"Error": err, | ||
}) | ||
} else { | ||
alreadySend[p] = append(alreadySend[p], mail.ID) | ||
} | ||
err = writeToFile(alreadySend, m.Config.General.File) | ||
if err != nil { | ||
m.Error("File Error", map[string]interface{}{ | ||
"Error": err, | ||
}) | ||
m.Debug("In mail2most Run, Before writeToFile on " + m.Config.General.File,nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put the additional logging information into
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
err = writeToFile(alreadySend, m.Config.General.File) | ||
|
||
if err != nil { | ||
m.Error("File Error", map[string]interface{}{ | ||
"Error": err, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,14 @@ import ( | |
|
||
func (m Mail2Most) mlogin(profile int) (*model.Client4, error) { | ||
c := model.NewAPIv4Client(m.Config.Profiles[profile].Mattermost.URL) | ||
|
||
m.Info("in mlogin", nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
no need to have this on Info logging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if m.Config.Profiles[profile].Mattermost.Username != "" && m.Config.Profiles[profile].Mattermost.Password != "" { | ||
_, resp := c.Login(m.Config.Profiles[profile].Mattermost.Username, m.Config.Profiles[profile].Mattermost.Password) | ||
me, resp := c.Login(m.Config.Profiles[profile].Mattermost.Username, m.Config.Profiles[profile].Mattermost.Password) | ||
if resp.Error != nil { | ||
return nil, resp.Error | ||
} | ||
m.Config.Profiles[profile].Mattermost.UserId = me.Id | ||
|
||
} else if m.Config.Profiles[profile].Mattermost.AccessToken != "" { | ||
c.AuthToken = m.Config.Profiles[profile].Mattermost.AccessToken | ||
c.AuthType = "BEARER" | ||
|
@@ -28,7 +30,9 @@ func (m Mail2Most) mlogin(profile int) (*model.Client4, error) { | |
return nil, err | ||
} | ||
u := model.UserFromJson(r.Body) | ||
|
||
m.Config.Profiles[profile].Mattermost.Username = u.Email | ||
m.Config.Profiles[profile].Mattermost.UserId = u.Id | ||
} else { | ||
return nil, fmt.Errorf("no username, password or token is set") | ||
} | ||
|
@@ -59,6 +63,7 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error { | |
if err != nil { | ||
return err | ||
} | ||
|
||
defer c.Logout() | ||
|
||
// check if body is base64 encoded | ||
|
@@ -112,13 +117,13 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error { | |
email := fmt.Sprintf("%s@%s", mail.From[0].MailboxName, mail.From[0].HostName) | ||
user, resp := c.GetUserByEmail(email, "") | ||
if resp.Error != nil { | ||
m.Debug("user not found in system", map[string]interface{}{"error": resp.Error}) | ||
m.Debug("user not found in system for email " + email, map[string]interface{}{"error": resp.Error}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be more precise I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about
|
||
msg += m.getFromLine(profile, mail.From[0].PersonalName, email) | ||
} else { | ||
msg += m.getFromLine(profile, "@"+user.Username, email) | ||
} | ||
} | ||
|
||
//m.Debug("Before SubjectOnly/BodyOnly " + err.Error,nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed i guess? |
||
if m.Config.Profiles[profile].Mattermost.SubjectOnly && m.Config.Profiles[profile].Mattermost.BodyOnly { | ||
err := fmt.Errorf("config defines SubjectOnly and BodyOnly to be true which exclude each other") | ||
m.Error("Configuration inconsistency found", map[string]interface{}{"Config.Profile.Mattermost.SubjectOnly": true, "Config.Profile.Mattermost.BodyOnly": true, "error": err}) | ||
|
@@ -190,33 +195,24 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error { | |
return err | ||
} | ||
} | ||
|
||
m.Debug("In PostMattermost, Before m.Config.Profiles[profile].Mattermost.Users treatment",nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the others, adding additional information as seperate |
||
if len(m.Config.Profiles[profile].Mattermost.Users) > 0 { | ||
|
||
var ( | ||
me *model.User | ||
resp *model.Response | ||
) | ||
|
||
// who am i | ||
// user is defined by its email address | ||
if strings.Contains(m.Config.Profiles[profile].Mattermost.Username, "@") { | ||
me, resp = c.GetUserByEmail(m.Config.Profiles[profile].Mattermost.Username, "") | ||
if resp.Error != nil { | ||
return resp.Error | ||
} | ||
} else { | ||
me, resp = c.GetUserByEmail(m.Config.Profiles[profile].Mattermost.Username, "") | ||
if resp.Error != nil { | ||
return resp.Error | ||
} | ||
} | ||
myid := me.Id | ||
myid := m.Config.Profiles[profile].Mattermost.UserId | ||
|
||
for _, user := range m.Config.Profiles[profile].Mattermost.Users { | ||
var ( | ||
u *model.User | ||
) | ||
m.Debug("In PostMattermost, In m.Config.Profiles[profile].Mattermost.Users treatment ", map[string]interface{}{"length of user name": len(user)}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this is debug line is really needed since it's now catched with a proper error instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if len(user) == 0 { | ||
return errors.New("User to send message to in Mattermost seems to be empty") | ||
} | ||
// user is defined by its email address | ||
if strings.Contains(user, "@") { | ||
u, resp = c.GetUserByEmail(user, "") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be more like
I think the "Email not set as synced" part can be removed this its now the correct default behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for reference: putting additional information into the additional information part (
map[string]interface
) allows the logger to seperate this information and depending on the logging type (text/json) to seperate the fields so they can be read and parsed by a logging backend correctlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you fix it pls