-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
reply issue by email #13585
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
reply issue by email #13585
Changes from 26 commits
404ae49
61b9c64
539421d
ca8a716
30d3479
d5dac5d
c95f015
e357517
e6ada29
4800de2
5b5fb6c
77cedeb
074e6d2
4baedb5
08345f0
560f48a
f30caf9
f076123
b00df2e
47df1c9
2923155
4176a92
e881e4c
cffb646
99921b3
65c26ca
68c69bb
4069ceb
3cfe21e
325392e
5589c19
e1948eb
fe2f5e6
9670bc1
0fc7000
f0d9b54
0bad64a
bbb2513
af5a825
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 |
---|---|---|
|
@@ -24,7 +24,6 @@ | |
created_unix: 946684810 | ||
updated_unix: 978307190 | ||
|
||
|
||
- | ||
id: 3 | ||
repo_id: 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/markup/markdown" | ||
"code.gitea.io/gitea/modules/references" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
|
@@ -713,6 +714,43 @@ func (c *Comment) LoadPushCommits() (err error) { | |
return err | ||
} | ||
|
||
// ReplyReference returns tokenized address to use for email reply headers | ||
func (c *Comment) ReplyReference(key string) string { | ||
if err := c.LoadIssue(); err != nil { | ||
log.Error("comment.LoadIssue(): %v", err) | ||
return "" | ||
} | ||
|
||
if err := c.Issue.LoadRepo(); err != nil { | ||
log.Error("Issue.LoadRepo(): %v", err) | ||
return "" | ||
} | ||
|
||
var path string | ||
if c.Issue.IsPull { | ||
path = "pulls" | ||
} else { | ||
path = "issues" | ||
} | ||
|
||
if len(key) > 0 { | ||
return fmt.Sprintf("%s/%s/%d#%s?%s@%s", | ||
c.Issue.Repo.FullName(), | ||
path, | ||
c.Issue.Index, | ||
c.HashTag(), | ||
key, | ||
setting.Domain) | ||
} | ||
|
||
return fmt.Sprintf("%s/%s/%d#%s@%s", | ||
c.Issue.Repo.FullName(), | ||
path, | ||
c.Issue.Index, | ||
c.HashTag(), | ||
setting.Domain) | ||
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. I've seen this block of code at least twice now. What about refactoring into a new function? 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. I'm sorry, but I hasn't found it. can you point it out please? Thanks. |
||
} | ||
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. As above, these Message-ID should follow RFC encoding |
||
|
||
func createComment(e db.Engine, opts *CreateCommentOptions) (_ *Comment, err error) { | ||
var LabelID int64 | ||
if opts.Label != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package setting | ||
|
||
import "code.gitea.io/gitea/modules/log" | ||
|
||
// MailReceiver represents mail receive service. | ||
type MailReceiver struct { | ||
ReceiveEmail string | ||
ReceiveBox string | ||
QueueLength int | ||
Host string | ||
User, Passwd string | ||
IsTLSEnabled bool | ||
DeleteReadMail bool | ||
} | ||
|
||
var ( | ||
// MailRecieveService mail receive config | ||
MailRecieveService *MailReceiver | ||
) | ||
|
||
func newMailRecieveService() { | ||
sec := Cfg.Section("mail_receive") | ||
// Check mailer setting. | ||
if !sec.Key("ENABLED").MustBool() { | ||
return | ||
} | ||
|
||
MailRecieveService = &MailReceiver{ | ||
ReceiveEmail: sec.Key("RECEIVE_EMAIL").String(), | ||
ReceiveBox: sec.Key("RECEIVE_BOX").MustString("INBOX"), | ||
QueueLength: sec.Key("READ_BUFFER_LEN").MustInt(100), | ||
Host: sec.Key("HOST").String(), | ||
User: sec.Key("USER").String(), | ||
Passwd: sec.Key("PASSWD").String(), | ||
IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(true), | ||
DeleteReadMail: sec.Key("DELETE_READ_MAIL").MustBool(false), | ||
} | ||
|
||
log.Info("Mail Receive Service Enabled") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package imap | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
var ( | ||
c *Client | ||
) | ||
|
||
// FetchAllUnreadMails fetch all unread mails | ||
func FetchAllUnreadMails() (err error) { | ||
if c == nil { | ||
c, err = NewImapClient(ClientInitOpt{ | ||
Addr: setting.MailRecieveService.Host, | ||
UserName: setting.MailRecieveService.User, | ||
Passwd: setting.MailRecieveService.Passwd, | ||
IsTLS: setting.MailRecieveService.IsTLSEnabled, | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
if mailReadQueue != nil && !mailReadQueue.IsEmpty() { | ||
return | ||
} | ||
|
||
mails, err := c.GetUnreadMails(setting.MailRecieveService.ReceiveBox, 100) | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, mail := range mails { | ||
err = mailReadQueue.Push(mail) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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.
https://datatracker.ietf.org/doc/html/rfc2392
The
key
might need to be encoded.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.
But this format is too strict to produce a meaningfull messgae, I wonder.
example of this format:
and github also not use this format:

Uh oh!
There was an error while loading. Please reload this page.
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.
An word is either an atom or a quoted string.
https://jkorpela.fi/rfc/822addr.html
Positively speaking, this means that the valid constituents of an atom are the following:
Not that strict.
I mean maybe we need a sanitizer or encoder for such format. Otherwise there may be potential bugs.