updated webclient setttings
This commit is contained in:
+36
-11
@@ -12,13 +12,21 @@ type FilterAction struct {
|
||||
Folder string // non-empty: store here instead of INBOX
|
||||
MarkRead bool
|
||||
Drop bool // don't store at all
|
||||
// ForwardTo: non-empty means also relay a copy of this message out to this
|
||||
// address — see smtpserver's deliverLocally, which actually sends it (this
|
||||
// package has no outbound SMTP capability of its own). KeepCopy controls whether
|
||||
// the recipient's own local copy is still stored too.
|
||||
ForwardTo string
|
||||
KeepCopy bool
|
||||
}
|
||||
|
||||
// ApplyRules evaluates a mailbox's filter rules in priority order and returns the
|
||||
// first match's action (zero value if none match, meaning "store in INBOX, unread").
|
||||
// headers should have "from"/"to"/"subject" keys — rules run at delivery time, before
|
||||
// the message is encrypted and stored, so real header values are available, not just
|
||||
// the plaintext cache columns used for fast IMAP listing.
|
||||
// headers should have "from"/"to"/"subject"/"body"/"has_attachment"/"recipient_type"
|
||||
// keys — rules run at delivery time, before the message is encrypted and stored, so
|
||||
// real header/body values are available, not just the plaintext cache columns used
|
||||
// for fast IMAP listing. has_attachment is "yes"/"no" and recipient_type is
|
||||
// "to"/"cc"/"bcc", both computed by the caller rather than being real headers.
|
||||
func (s *Store) ApplyRules(mailboxID int64, headers map[string]string) (FilterAction, error) {
|
||||
rules, err := s.DB.ListRulesForMailbox(mailboxID)
|
||||
if err != nil {
|
||||
@@ -43,6 +51,8 @@ func (s *Store) ApplyRules(mailboxID int64, headers map[string]string) (FilterAc
|
||||
return FilterAction{Drop: true}, nil
|
||||
case "mark_read":
|
||||
return FilterAction{MarkRead: true}, nil
|
||||
case "forward":
|
||||
return FilterAction{ForwardTo: r.ActionValue, KeepCopy: r.ActionOptions().KeepCopy}, nil
|
||||
}
|
||||
}
|
||||
return FilterAction{}, nil
|
||||
@@ -68,16 +78,31 @@ func ruleMatches(r db.MailboxFilterRule, headers map[string]string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// matchCondition compares a header's actual value against a condition's target.
|
||||
// target may hold several "\n"-joined values (the rule builder's chip input, e.g.
|
||||
// multiple From addresses or multiple subject keywords) — matches if any one does,
|
||||
// mirroring how a real mail client's "is any of" condition works.
|
||||
func matchCondition(op, value, target string) bool {
|
||||
value = strings.ToLower(value)
|
||||
target = strings.ToLower(target)
|
||||
switch op {
|
||||
case "contains":
|
||||
return strings.Contains(value, target)
|
||||
case "equals":
|
||||
return value == target
|
||||
case "starts_with":
|
||||
return strings.HasPrefix(value, target)
|
||||
for _, t := range strings.Split(target, "\n") {
|
||||
t = strings.ToLower(strings.TrimSpace(t))
|
||||
if t == "" {
|
||||
continue
|
||||
}
|
||||
switch op {
|
||||
case "contains":
|
||||
if strings.Contains(value, t) {
|
||||
return true
|
||||
}
|
||||
case "equals":
|
||||
if value == t {
|
||||
return true
|
||||
}
|
||||
case "starts_with":
|
||||
if strings.HasPrefix(value, t) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user