This commit is contained in:
aozhiwei 2024-08-20 14:12:59 +08:00
parent ff4f33b972
commit 89e94a8557

View File

@ -139,12 +139,44 @@ func (this *player) GetAttachment(mails []common.Mail, c *gin.Context) {
return return
} }
if errCode, err := q5.ToInt64Ex(rspObj.ErrCode); err == nil && errCode == 0 { if errCode, err := q5.ToInt64Ex(rspObj.ErrCode); err == nil && errCode == 0 {
this.DeleteMails(mails) this.ReceivedMails(mails)
} }
c.String(200, rsp.GetRawData()) c.String(200, rsp.GetRawData())
}) })
} }
func (this *player) ReceivedMails(mails []common.Mail) error {
this.checkLock()
var resultErr error
var nowTime int64
for _, m := range(mails) {
if m.IsValid(this) {
mi := this.getInbox(m.GetMailId())
if mi == nil {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi = new(inbox)
mi.mailId = m.GetMailId()
mi.state = constant.INBOX_STATE_DELETED
mi.expireTime = m.GetExpireTime()
this.inboxHash[mi.mailId] = mi
} else if mi.state != constant.INBOX_STATE_DELETED {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi.state = constant.INBOX_STATE_DELETED
mi.expireTime = m.GetExpireTime()
}
}
}
return resultErr
}
func (this *player) DeleteMails(mails []common.Mail) error { func (this *player) DeleteMails(mails []common.Mail) error {
this.checkLock() this.checkLock()
var resultErr error var resultErr error
@ -153,7 +185,7 @@ func (this *player) DeleteMails(mails []common.Mail) error {
if m.IsValid(this) { if m.IsValid(this) {
mi := this.getInbox(m.GetMailId()) mi := this.getInbox(m.GetMailId())
if mi == nil { if mi == nil {
if m.HasAttachment() { if !m.HasAttachment() {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime()) err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil { if err != nil {
resultErr = err resultErr = err
@ -166,7 +198,7 @@ func (this *player) DeleteMails(mails []common.Mail) error {
this.inboxHash[mi.mailId] = mi this.inboxHash[mi.mailId] = mi
} }
} else if mi.state != constant.INBOX_STATE_DELETED { } else if mi.state != constant.INBOX_STATE_DELETED {
if !m.HasAttachment() || mi.state != constant.INBOX_STATE_RECEIVED { if !m.HasAttachment() || mi.state == constant.INBOX_STATE_RECEIVED {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime()) err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil { if err != nil {
resultErr = err resultErr = err
@ -190,10 +222,10 @@ func (this *player) checkLock() {
func (this *player) load() { func (this *player) load() {
f5.GetGoStyleDb().RawQuery( f5.GetGoStyleDb().RawQuery(
constant.MAIL_DB, constant.MAIL_DB,
"SELECT * FROM t_inbox WHERE account_id=? AND expiretime<?", "SELECT * FROM t_inbox WHERE account_id=? AND expiretime>?",
[]string{ []string{
this.GetAccountId(), this.GetAccountId(),
q5.ToString(f5.GetApp().GetRealSeconds() + 3600 * 24 * 7), q5.ToString(f5.GetApp().GetRealSeconds() - 3600 * 24 * 7),
}, },
func (err error, ds *f5.DataSet) { func (err error, ds *f5.DataSet) {
if err != nil { if err != nil {