Skip to content

Commit

Permalink
feature/v2.8.1 (#239)
Browse files Browse the repository at this point in the history
修复ssl证书校验失败
部分客户端兼容性修复
修复邮件移动失败问题
支持“广告箱”
  • Loading branch information
Jinnrry authored Jan 6, 2025
1 parent 5af46b3 commit 69800a8
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 1,166 deletions.
4 changes: 4 additions & 0 deletions server/controllers/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func GetUserGroup(ctx *context.Context, w http.ResponseWriter, req *http.Request
Label: i18n.GetText(ctx.Lang, "sketch"),
Tag: dto.SearchTag{Type: 1, Status: 0}.ToString(),
},
{
Label: i18n.GetText(ctx.Lang, "junk"),
Tag: dto.SearchTag{Type: -1, Status: 5}.ToString(),
},
{
Label: i18n.GetText(ctx.Lang, "deleted"),
Tag: dto.SearchTag{Type: -1, Status: 3}.ToString(),
Expand Down
6 changes: 5 additions & 1 deletion server/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func Init(version string) error {

if version != "" && v.Info != version && version != "test" {
v.Info = version
Instance.Update(&v)
if v.Id == 0 {
Instance.Insert(&v)
} else {
Instance.Update(&v)
}
}

if config.Instance.LogLevel == "debug" {
Expand Down
2 changes: 1 addition & 1 deletion server/hooks/spam_block/spam_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *SpamBlock) ReceiveParseAfter(ctx *context.Context, email *parsemail.Ema
}

if maxClass != 0 && maxScore > s.cfg.Threshold/100 {
email.Status = 3
email.Status = 5
}
}

Expand Down
2 changes: 2 additions & 0 deletions server/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
"ip_taps": "这是你服务器IP,确保这个IP正确",
"invalid_email_address": "无效的邮箱地址!",
"deleted": "垃圾箱",
"junk": "广告箱",
}
en = map[string]string{
"all_email": "All Email",
Expand All @@ -30,6 +31,7 @@ var (
"ip_taps": "This is your server's IP, make sure it is correct.",
"invalid_email_address": "Invalid e-mail address!",
"deleted": "Deleted",
"junk": "Junk",
}
)

Expand Down
1 change: 0 additions & 1 deletion server/listen/imap_server/imap_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func StarTLS() {
},
Caps: imap.CapSet{
imap.CapIMAP4rev1: {},
imap.CapIMAP4rev2: {},
},
TLSConfig: tlsConfig,
InsecureAuth: false,
Expand Down
14 changes: 3 additions & 11 deletions server/listen/imap_server/imap_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,24 +400,16 @@ func TestMove(t *testing.T) {
func TestCopy(t *testing.T) {
clientLogin.Select("INBOX", &imap.SelectOptions{}).Wait()

res, err := clientLogin.Copy(imap.UIDSetNum(25), "Junk").Wait()
_, err := clientLogin.Copy(imap.UIDSetNum(25), "Junk").Wait()
if err != nil {
t.Errorf("%+v", err)
}
t.Logf("%+v", res)

if !res.DestUIDs.Contains(33) {
t.Errorf("TestCopy Error")
}

res, err = clientLogin.Copy(imap.UIDSetNum(27), "一级菜单").Wait()
_, err = clientLogin.Copy(imap.UIDSetNum(27), "一级菜单").Wait()
if err != nil {
t.Errorf("%+v", err)
}
t.Logf("%+v", res)
if !res.DestUIDs.Contains(34) {
t.Errorf("TestCopy Error")
}

}

func TestNoop(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions server/listen/imap_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type serverSession struct {
status Status
currentMailbox string
connectTime time.Time
deleteUidList []int
}

// NewSession creates a new IMAP session.
Expand Down
23 changes: 17 additions & 6 deletions server/listen/imap_server/session_expunge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ import (
)

func (s *serverSession) Expunge(w *imapserver.ExpungeWriter, uids *imap.UIDSet) error {
if uids == nil {
if uids == nil && len(s.deleteUidList) == 0 {
return nil
}

uidList := []int{}
for _, uidRange := range *uids {
if uidRange.Start > 0 && uidRange.Stop > 0 {
for i := uidRange.Start; i <= uidRange.Stop; i++ {
uidList = append(uidList, cast.ToInt(uint32(i)))

if uids != nil {
for _, uidRange := range *uids {
if uidRange.Start > 0 && uidRange.Stop > 0 {
for i := uidRange.Start; i <= uidRange.Stop; i++ {
uidList = append(uidList, cast.ToInt(uint32(i)))
}
}
}
}

if len(s.deleteUidList) > 0 {
uidList = append(uidList, s.deleteUidList...)
}

if len(uidList) == 0 {
return nil
}

err := del_email.DelByUID(s.ctx, uidList)
s.deleteUidList = []int{}
if err != nil {
return &imap.Error{
Type: imap.StatusResponseTypeNo,
Expand Down
10 changes: 9 additions & 1 deletion server/listen/imap_server/session_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ func write(ctx *context.Context, w *imapserver.FetchWriter, emailList []*respons
if section.Specifier == imap.PartSpecifierHeader {
var b bytes.Buffer
parseEmail := parsemail.NewEmailFromModel(email.Email)
for _, field := range section.HeaderFields {
fields := section.HeaderFields

if fields == nil || len(fields) == 0 {
fields = []string{
"date", "subject", "from", "to", "cc", "message-id", "content-type",
}
}

for _, field := range fields {
switch field {
case "date":
fmt.Fprintf(&b, "Date: %s\r\n", email.CreateTime.Format(time.RFC1123Z))
Expand Down
9 changes: 4 additions & 5 deletions server/listen/imap_server/session_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/Jinnrry/pmail/services/list"
"github.com/emersion/go-imap/v2"
"github.com/emersion/go-imap/v2/imapserver"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
)

Expand All @@ -14,7 +13,7 @@ func (s *serverSession) Search(kind imapserver.NumKind, criteria *imap.SearchCri

for _, uidSet := range criteria.UID {
for _, uid := range uidSet {
res := list.GetUEListByUID(s.ctx, s.currentMailbox, cast.ToInt(uid.Start), cast.ToInt(uid.Stop), nil)
res := list.GetUEListByUID(s.ctx, s.currentMailbox, cast.ToInt(uint32(uid.Start)), cast.ToInt(uint32(uid.Stop)), nil)
retList = append(retList, res...)
}
}
Expand All @@ -23,24 +22,24 @@ func (s *serverSession) Search(kind imapserver.NumKind, criteria *imap.SearchCri
if kind == imapserver.NumKindSeq {
idList := imap.SeqSet{}
for _, data := range retList {
log.WithContext(s.ctx).Debugf("Search Seq result: UID: %d EmailID:%d", data.ID, data.EmailID)
idList = append(idList, imap.SeqRange{
Start: cast.ToUint32(data.SerialNumber),
Stop: cast.ToUint32(data.SerialNumber),
})
}
ret.All = idList
ret.Count = uint32(len(retList))
} else {
idList := imap.UIDSet{}
for _, data := range retList {
log.WithContext(s.ctx).Debugf("Search UID result: UID: %d EmailID:%d", data.ID, data.EmailID)

idList = append(idList, imap.UIDRange{
Start: imap.UID(data.ID),
Stop: imap.UID(data.ID),
})
}
ret.UID = true
ret.All = idList
ret.Count = uint32(len(retList))
}
return ret, nil
}
31 changes: 20 additions & 11 deletions server/listen/imap_server/session_store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package imap_server

import (
"github.com/Jinnrry/pmail/dto/response"
"github.com/Jinnrry/pmail/services/detail"
"github.com/Jinnrry/pmail/services/list"
"github.com/Jinnrry/pmail/utils/array"
Expand All @@ -10,38 +11,46 @@ import (
)

func (s *serverSession) Store(w *imapserver.FetchWriter, numSet imap.NumSet, flags *imap.StoreFlags, options *imap.StoreOptions) error {

if flags.Op == imap.StoreFlagsSet {
return nil
}

if !array.InArray(imap.FlagSeen, flags.Flags) {
return nil
}
var emailList []*response.EmailResponseData

switch numSet.(type) {
case imap.SeqSet:
seqSet := numSet.(imap.SeqSet)
for _, seq := range seqSet {
emailList := list.GetEmailListByGroup(s.ctx, s.currentMailbox, list.ImapListReq{
res := list.GetEmailListByGroup(s.ctx, s.currentMailbox, list.ImapListReq{
Star: cast.ToInt(seq.Start),
End: cast.ToInt(seq.Stop),
}, false)
for _, data := range emailList {
detail.MakeRead(s.ctx, data.Id, flags.Op == imap.StoreFlagsAdd)
}
emailList = append(emailList, res...)
}

case imap.UIDSet:
uidSet := numSet.(imap.UIDSet)
for _, uid := range uidSet {
emailList := list.GetEmailListByGroup(s.ctx, s.currentMailbox, list.ImapListReq{
res := list.GetEmailListByGroup(s.ctx, s.currentMailbox, list.ImapListReq{
Star: cast.ToInt(uint32(uid.Start)),
End: cast.ToInt(uint32(uid.Stop)),
}, true)
for _, data := range emailList {
detail.MakeRead(s.ctx, data.Id, flags.Op == imap.StoreFlagsAdd)
}
emailList = append(emailList, res...)
}
}

if array.InArray(imap.FlagSeen, flags.Flags) && flags.Op == imap.StoreFlagsAdd {
for _, data := range emailList {
detail.MakeRead(s.ctx, data.Id, flags.Op == imap.StoreFlagsAdd)
}
}

if array.InArray(imap.FlagDeleted, flags.Flags) && flags.Op == imap.StoreFlagsAdd {
for _, data := range emailList {
s.deleteUidList = append(s.deleteUidList, data.UeId)
}
}

return nil
}
6 changes: 4 additions & 2 deletions server/services/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func GetGroupStatus(ctx *context.Context, groupName string, params []string) (st
case "MESSAGES":
db.Instance.Table("user_email").Select("count(1)").Where("group_id=?", group.ID).Get(&value)
case "UIDNEXT":
db.Instance.Table("email").Select("count(1)").Get(&value)
db.Instance.Table("user_email").Select("id").OrderBy("id desc").Get(&value)
value += 1
case "UIDVALIDITY":
value = group.ID
case "UNSEEN":
Expand All @@ -241,7 +242,8 @@ func GetGroupStatus(ctx *context.Context, groupName string, params []string) (st
case "MESSAGES":
value = getGroupNum(ctx, groupName, false)
case "UIDNEXT":
db.Instance.Table("email").Select("count(1)").Get(&value)
db.Instance.Table("user_email").Select("id").OrderBy("id desc").Get(&value)
value += 1
case "UIDVALIDITY":
value = models.GroupNameToCode[groupName]
case "UNSEEN":
Expand Down
2 changes: 1 addition & 1 deletion server/services/setup/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func CheckSSLCrtInfo() (int, time.Time, bool, error) {

nameMatchFail := true
for _, name := range cert.DNSNames {
if strings.Contains("imap", name) {
if strings.Contains(name, "imap") {
nameMatchFail = false
break
}
Expand Down
4 changes: 2 additions & 2 deletions server/services/setup/ssl/ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestCheckSSLCrtInfo(t *testing.T) {
config.Init()

got, got1, _, err := CheckSSLCrtInfo()
got, got1, match, err := CheckSSLCrtInfo()

fmt.Println(got, got1, err)
fmt.Println(got, got1, match, err)
}
59 changes: 0 additions & 59 deletions server/utils/goimap/action.go

This file was deleted.

15 changes: 0 additions & 15 deletions server/utils/goimap/dto.go

This file was deleted.

Loading

0 comments on commit 69800a8

Please sign in to comment.