mirror of
https://github.com/eoao/cloud-mail.git
synced 2026-05-06 21:51:48 +08:00
修复邮件数量统计错误
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { emailConst } from '../const/entity-const';
|
||||
|
||||
const analysisDao = {
|
||||
async numberCount(c) {
|
||||
const { results } = await c.env.db.prepare(`
|
||||
@@ -24,7 +26,7 @@ const analysisDao = {
|
||||
SUM(CASE WHEN type = 0 AND is_del = 0 THEN 1 ELSE 0 END) AS normalReceiveTotal,
|
||||
SUM(CASE WHEN type = 1 AND is_del = 0 THEN 1 ELSE 0 END) AS normalSendTotal
|
||||
FROM
|
||||
email
|
||||
email where status != ${emailConst.status.SAVING}
|
||||
) e
|
||||
CROSS JOIN (
|
||||
SELECT
|
||||
|
||||
@@ -62,7 +62,7 @@ export async function email(message, env, ctx) {
|
||||
|
||||
let { banEmail, banEmailType, availDomain } = await roleService.selectByUserId({ env: env }, account.userId);
|
||||
|
||||
if(!roleService.hasAvailDomainPerm(availDomain, message.to)) {
|
||||
if (!roleService.hasAvailDomainPerm(availDomain, message.to)) {
|
||||
message.setReject('Mailbox disabled');
|
||||
return;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ export async function email(message, env, ctx) {
|
||||
|
||||
if (banEmail.includes('*')) {
|
||||
|
||||
if (!banEmailHandler(banEmailType,message,email)) return
|
||||
if (!banEmailHandler(banEmailType, message, email)) return;
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export async function email(message, env, ctx) {
|
||||
|
||||
if (banDomain === receiveDomain) {
|
||||
|
||||
if (!banEmailHandler(banEmailType,message,email)) return
|
||||
if (!banEmailHandler(banEmailType, message, email)) return;
|
||||
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ export async function email(message, env, ctx) {
|
||||
|
||||
if (item.toLowerCase() === email.from.address.toLowerCase()) {
|
||||
|
||||
if (!banEmailHandler(banEmailType,message,email)) return
|
||||
if (!banEmailHandler(banEmailType, message, email)) return;
|
||||
|
||||
}
|
||||
|
||||
@@ -146,12 +146,12 @@ export async function email(message, env, ctx) {
|
||||
attachment.accountId = emailRow.accountId;
|
||||
});
|
||||
|
||||
if (attachments.length > 0 && await r2Service.hasOSS({env})) {
|
||||
try {
|
||||
try {
|
||||
if (attachments.length > 0 && await r2Service.hasOSS({ env })) {
|
||||
await attService.addAtt({ env }, attachments);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
emailRow = await emailService.completeReceive({ env }, account ? emailConst.status.RECEIVE : emailConst.status.NOONE, emailRow.emailId);
|
||||
@@ -225,11 +225,11 @@ ${params.text || emailUtils.htmlToText(params.content) || ''}
|
||||
}
|
||||
}
|
||||
|
||||
function banEmailHandler(banEmailType,message,email) {
|
||||
function banEmailHandler(banEmailType, message, email) {
|
||||
|
||||
if (banEmailType === roleConst.banEmailType.ALL) {
|
||||
message.setReject('Mailbox disabled');
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
if (banEmailType === roleConst.banEmailType.CONTENT) {
|
||||
@@ -238,6 +238,6 @@ function banEmailHandler(banEmailType,message,email) {
|
||||
email.attachments = [];
|
||||
}
|
||||
|
||||
return true
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import app from './hono/webs';
|
||||
import { email } from './email/email';
|
||||
import userService from './service/user-service';
|
||||
import verifyRecordService from './service/verify-record-service';
|
||||
import emailService from './service/email-service';
|
||||
export default {
|
||||
async fetch(req, env, ctx) {
|
||||
const url = new URL(req.url)
|
||||
@@ -20,5 +21,6 @@ export default {
|
||||
async scheduled(c, env, ctx) {
|
||||
await verifyRecordService.clearRecord({env})
|
||||
await userService.resetDaySendCount({ env })
|
||||
await emailService.completeReceiveAll({ env })
|
||||
},
|
||||
};
|
||||
|
||||
@@ -489,7 +489,8 @@ const emailService = {
|
||||
.where(and(
|
||||
inArray(email.userId, userIds),
|
||||
eq(email.type, type),
|
||||
eq(email.isDel, del)
|
||||
eq(email.isDel, del),
|
||||
ne(email.status, emailConst.status.SAVING),
|
||||
))
|
||||
.groupBy(email.userId);
|
||||
return result;
|
||||
@@ -611,6 +612,11 @@ const emailService = {
|
||||
}).where(eq(email.emailId, emailId)).returning().get();
|
||||
},
|
||||
|
||||
async completeReceiveAll(c) {
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.RECEIVE} WHERE status = ${emailConst.status.SAVING} AND EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
await c.env.db.prepare(`UPDATE email as e SET status = ${emailConst.status.NOONE} WHERE status = ${emailConst.status.SAVING} AND NOT EXISTS (SELECT 1 FROM account WHERE account_id = e.account_id)`).run();
|
||||
},
|
||||
|
||||
async batchDelete(c, params) {
|
||||
let { sendName, sendEmail, toEmail, subject, startTime, endTime, type } = params
|
||||
|
||||
|
||||
Reference in New Issue
Block a user