Feature/v2.9.2 (#344)
* feature/v2.9.0 ui优化 * add test case add test case * feature/v2.9.2 bug fix --------- Co-authored-by: Your Name <you@example.com>
This commit is contained in:
1 parent
68dc2f0f47
commit
6455635f74
11 files changed
+257
-66
No files matched your search
@@ -2,6 +2,7 @@ package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Jinnrry/pmail/consts"
|
||||
"github.com/Jinnrry/pmail/db"
|
||||
"github.com/Jinnrry/pmail/dto"
|
||||
"github.com/Jinnrry/pmail/dto/response"
|
||||
@@ -48,8 +49,18 @@ func genSQL(ctx *context.Context, count bool, tagInfo dto.SearchTag, keyword str
|
||||
}
|
||||
|
||||
if tagInfo.Status != -1 {
|
||||
sql += " and ue.status =? "
|
||||
sqlParams = append(sqlParams, tagInfo.Status)
|
||||
switch tagInfo.Status {
|
||||
case consts.EmailStatusDel:
|
||||
sql += " and (ue.status =? or ue.group_id=?) "
|
||||
sqlParams = append(sqlParams, tagInfo.Status, models.Deleted)
|
||||
case consts.EmailStatusDrafts:
|
||||
sql += " and (ue.status =? or ue.group_id=?) "
|
||||
sqlParams = append(sqlParams, tagInfo.Status, models.Drafts)
|
||||
case consts.EmailStatusJunk:
|
||||
sql += " and (ue.status =? or ue.group_id=?) "
|
||||
sqlParams = append(sqlParams, tagInfo.Status, models.Junk)
|
||||
}
|
||||
|
||||
} else if tagInfo.Status == -1 {
|
||||
if tagInfo.Type != 1 {
|
||||
sql += " and ue.status = 0"
|
||||
@@ -59,16 +70,25 @@ func genSQL(ctx *context.Context, count bool, tagInfo dto.SearchTag, keyword str
|
||||
}
|
||||
}
|
||||
|
||||
if tagInfo.Type != -1 {
|
||||
if tagInfo.Type == consts.EmailTypeReceive {
|
||||
sql += " and type =? "
|
||||
sqlParams = append(sqlParams, tagInfo.Type)
|
||||
} else if tagInfo.Type == consts.EmailTypeSend {
|
||||
sql += " and (type =? or ue.group_id=?)"
|
||||
sqlParams = append(sqlParams, tagInfo.Type, models.Sent)
|
||||
}
|
||||
|
||||
if tagInfo.GroupId != -1 {
|
||||
sql += " and ue.group_id=? "
|
||||
sqlParams = append(sqlParams, tagInfo.GroupId)
|
||||
if tagInfo.GroupId > 0 {
|
||||
sql += " and ue.group_id=? "
|
||||
sqlParams = append(sqlParams, tagInfo.GroupId)
|
||||
} else if tagInfo.GroupId == 0 && tagInfo.Status == -1 {
|
||||
sql += " and (ue.group_id=? or ue.group_id=0)"
|
||||
sqlParams = append(sqlParams, models.INBOX)
|
||||
}
|
||||
} else {
|
||||
sql += " and ue.group_id=0 "
|
||||
sql += " and (ue.group_id=0 or ue.group_id =?) "
|
||||
sqlParams = append(sqlParams, models.INBOX)
|
||||
}
|
||||
|
||||
if keyword != "" {
|
||||
|
||||
@@ -86,7 +86,63 @@ func DoRule(ctx *context.Context, rule *dto.Rule, email *parsemail.Email, user *
|
||||
log.WithContext(ctx).Errorf("Forward Error:%v", err)
|
||||
}
|
||||
case dto.MOVE:
|
||||
_, err := db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).Cols("group_id").Update(map[string]interface{}{"group_id": cast.ToInt(rule.Params)})
|
||||
doMove(ctx, rule, email, user)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func doMove(ctx *context.Context, rule *dto.Rule, email *parsemail.Email, user *models.User) {
|
||||
|
||||
groupId := cast.ToInt(rule.Params)
|
||||
switch groupId {
|
||||
case models.INBOX:
|
||||
_, err := db.Instance.Table(&models.Email{}).Where("id=?", email.MessageId).
|
||||
Cols("type").Update(map[string]interface{}{"type": consts.EmailTypeReceive})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
_, err = db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).
|
||||
Cols("group_id", "status").Update(map[string]interface{}{"group_id": 0, "status": 0})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
case models.Sent:
|
||||
_, err := db.Instance.Table(&models.Email{}).Where("id=?", email.MessageId).
|
||||
Cols("type").Update(map[string]interface{}{"type": consts.EmailTypeSend})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
_, err = db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).
|
||||
Cols("group_id", "status").Update(map[string]interface{}{"group_id": 0, "status": 0})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
case models.Drafts:
|
||||
_, err := db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).
|
||||
Cols("group_id", "status").Update(map[string]interface{}{"group_id": 0, "status": consts.EmailStatusDrafts})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
case models.Deleted:
|
||||
_, err := db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).
|
||||
Cols("group_id", "status").Update(map[string]interface{}{"group_id": 0, "status": consts.EmailStatusDel})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
case models.Junk:
|
||||
_, err := db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).
|
||||
Cols("group_id", "status").Update(map[string]interface{}{"group_id": 0, "status": consts.EmailStatusJunk})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
_, err := db.Instance.Table(&models.UserEmail{}).Where("email_id=? and user_id=?", email.MessageId, rule.UserId).Cols("group_id").Update(map[string]interface{}{"group_id": groupId})
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("sqlERror :%v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user