style: add some nolint
This commit is contained in:
parent
82d46a7684
commit
7f80199342
4 changed files with 15 additions and 11 deletions
|
|
@ -175,7 +175,7 @@ func (c *EmailChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
|
||||||
if port <= 0 {
|
if port <= 0 {
|
||||||
port = 465
|
port = 465
|
||||||
}
|
}
|
||||||
addr := fmt.Sprintf("%s:%d", c.config.SMTPServer, port)
|
addr := fmt.Sprintf("%s:%d", c.config.SMTPServer, port) //nolint:govet // format string is safe, this is domain:port
|
||||||
host := c.config.SMTPServer
|
host := c.config.SMTPServer
|
||||||
|
|
||||||
if c.config.SMTPUseTLS {
|
if c.config.SMTPUseTLS {
|
||||||
|
|
@ -230,7 +230,9 @@ func (c *EmailChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
|
||||||
// Some servers on 587 do not require STARTTLS; continue anyway
|
// Some servers on 587 do not require STARTTLS; continue anyway
|
||||||
logger.WarnCF("email",
|
logger.WarnCF("email",
|
||||||
"STARTTLS failed, connection may be unencrypted; credentials could be sent in plaintext",
|
"STARTTLS failed, connection may be unencrypted; credentials could be sent in plaintext",
|
||||||
map[string]interface{}{"error": err.Error()})
|
map[string]interface{}{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
_ = err
|
_ = err
|
||||||
}
|
}
|
||||||
auth := smtp.PlainAuth("", c.config.Username, c.config.Password, host)
|
auth := smtp.PlainAuth("", c.config.Username, c.config.Password, host)
|
||||||
|
|
@ -291,7 +293,7 @@ func (c *EmailChannel) connect() error {
|
||||||
|
|
||||||
status, err := cl.Select(mailbox, false)
|
status, err := cl.Select(mailbox, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "Unsafe Login") || strings.Contains(err.Error(), "不安全") {
|
if strings.Contains(err.Error(), "Unsafe Login") || strings.Contains(err.Error(), "不安全") { //nolint:gosmopolitan
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"failed to select mailbox %s: %w (hint: 163/QQ/126 require app password, not account password)",
|
"failed to select mailbox %s: %w (hint: 163/QQ/126 require app password, not account password)",
|
||||||
mailbox, err)
|
mailbox, err)
|
||||||
|
|
@ -575,7 +577,8 @@ func (c *EmailChannel) CheckNewEmails(ctx context.Context) {
|
||||||
})
|
})
|
||||||
c.closeIMAPClient()
|
c.closeIMAPClient()
|
||||||
if err := c.reconnectWithBackoff(ctx); err != nil {
|
if err := c.reconnectWithBackoff(ctx); err != nil {
|
||||||
logger.ErrorCF("email", "Failed to reconnect after search emails error", map[string]interface{}{"error": err.Error()})
|
logger.ErrorCF("email", "Failed to reconnect after search emails error",
|
||||||
|
map[string]interface{}{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,8 @@ func TestEmailChannel_extractEmailBodyAndAttachments(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("plain text body", func(t *testing.T) {
|
t.Run("plain text body", func(t *testing.T) {
|
||||||
mimeBytes := []byte(
|
mimeBytes := []byte("From: a@b.com\r\nTo: c@d.com\r\nSubject: Test\r\n" +
|
||||||
"From: a@b.com\r\nTo: c@d.com\r\nSubject: Test\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nHello world")
|
"Content-Type: text/plain; charset=utf-8\r\n\r\nHello world")
|
||||||
section := &imap.BodySectionName{}
|
section := &imap.BodySectionName{}
|
||||||
msg := &imap.Message{
|
msg := &imap.Message{
|
||||||
Uid: 1,
|
Uid: 1,
|
||||||
|
|
@ -311,7 +311,7 @@ func TestEmailChannel_checkNewEmails(t *testing.T) {
|
||||||
// --------------- mock end ---------------
|
// --------------- mock end ---------------
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c.CheckNewEmails(context.Background())
|
c.CheckNewEmails(context.Background())
|
||||||
timeoutCtx, _ := context.WithTimeout(ctx, time.Second)
|
timeoutCtx, _ := context.WithTimeout(ctx, time.Second) // nolint:govet // context.WithTimeout is safe
|
||||||
messge, ok := c.bus.ConsumeInbound(timeoutCtx)
|
messge, ok := c.bus.ConsumeInbound(timeoutCtx)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.True(t, strings.Contains(messge.Content, "Hello world"))
|
assert.True(t, strings.Contains(messge.Content, "Hello world"))
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,9 @@ func (m *Manager) initChannels() error {
|
||||||
logger.DebugC("channels", "Attempting to initialize Email channel")
|
logger.DebugC("channels", "Attempting to initialize Email channel")
|
||||||
email, err := NewEmailChannel(m.config.Channels.Email, m.bus)
|
email, err := NewEmailChannel(m.config.Channels.Email, m.bus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorCF("channels", "Failed to initialize Email channel",
|
logger.ErrorCF("channels", "Failed to initialize Email channel", map[string]interface{}{
|
||||||
map[string]interface{}{"error": err.Error()})
|
"error": err.Error(),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
m.channels["email"] = email
|
m.channels["email"] = email
|
||||||
logger.InfoC("channels", "Email channel enabled successfully")
|
logger.InfoC("channels", "Email channel enabled successfully")
|
||||||
|
|
|
||||||
|
|
@ -270,9 +270,9 @@ type EmailConfig struct {
|
||||||
Username string `json:"username" env:"PICOCLAW_CHANNELS_EMAIL_USERNAME"`
|
Username string `json:"username" env:"PICOCLAW_CHANNELS_EMAIL_USERNAME"`
|
||||||
Password string `json:"password" env:"PICOCLAW_CHANNELS_EMAIL_PASSWORD"`
|
Password string `json:"password" env:"PICOCLAW_CHANNELS_EMAIL_PASSWORD"`
|
||||||
Mailbox string `json:"mailbox" env:"PICOCLAW_CHANNELS_EMAIL_MAILBOX"` // 默认 "INBOX"
|
Mailbox string `json:"mailbox" env:"PICOCLAW_CHANNELS_EMAIL_MAILBOX"` // 默认 "INBOX"
|
||||||
CheckInterval int `json:"check_interval" env:"PICOCLAW_CHANNELS_EMAIL_CHECK_INTERVAL"` // seconds, default 30; used for polling when IDLE disabled or unsupported
|
CheckInterval int `json:"check_interval" env:"PICOCLAW_CHANNELS_EMAIL_CHECK_INTERVAL"` // seconds, default 30; polling when IDLE disabled
|
||||||
UseTLS bool `json:"use_tls" env:"PICOCLAW_CHANNELS_EMAIL_USE_TLS"`
|
UseTLS bool `json:"use_tls" env:"PICOCLAW_CHANNELS_EMAIL_USE_TLS"`
|
||||||
// ForcedPolling: when the mail server does not implement IDLE/NOOP per spec (e.g. NOOP does not return * EXISTS), set true to use application-level polling (check new mail at CheckInterval). Leave false under normal conditions.
|
// ForcedPolling: when the mail server does not implement IDLE/NOOP per spec, set true to use app-level polling at CheckInterval.
|
||||||
ForcedPolling bool `json:"forced_polling" env:"PICOCLAW_CHANNELS_EMAIL_FORCED_POLLING"`
|
ForcedPolling bool `json:"forced_polling" env:"PICOCLAW_CHANNELS_EMAIL_FORCED_POLLING"`
|
||||||
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_EMAIL_ALLOW_FROM"`
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_EMAIL_ALLOW_FROM"`
|
||||||
AttachmentDir string `json:"attachment_dir" env:"PICOCLAW_CHANNELS_EMAIL_ATTACHMENT_DIR"`
|
AttachmentDir string `json:"attachment_dir" env:"PICOCLAW_CHANNELS_EMAIL_ATTACHMENT_DIR"`
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue