mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
修复邮件数量统计错误
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { emailConst } from '../const/entity-const';
|
||||||
|
|
||||||
const analysisDao = {
|
const analysisDao = {
|
||||||
async numberCount(c) {
|
async numberCount(c) {
|
||||||
const { results } = await c.env.db.prepare(`
|
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 = 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
|
SUM(CASE WHEN type = 1 AND is_del = 0 THEN 1 ELSE 0 END) AS normalSendTotal
|
||||||
FROM
|
FROM
|
||||||
email
|
email where status != ${emailConst.status.SAVING}
|
||||||
) e
|
) e
|
||||||
CROSS JOIN (
|
CROSS JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export async function email(message, env, ctx) {
|
|||||||
|
|
||||||
let { banEmail, banEmailType, availDomain } = await roleService.selectByUserId({ env: env }, account.userId);
|
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');
|
message.setReject('Mailbox disabled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ export async function email(message, env, ctx) {
|
|||||||
|
|
||||||
if (banEmail.includes('*')) {
|
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 (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 (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;
|
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);
|
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);
|
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) {
|
if (banEmailType === roleConst.banEmailType.ALL) {
|
||||||
message.setReject('Mailbox disabled');
|
message.setReject('Mailbox disabled');
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (banEmailType === roleConst.banEmailType.CONTENT) {
|
if (banEmailType === roleConst.banEmailType.CONTENT) {
|
||||||
@@ -238,6 +238,6 @@ function banEmailHandler(banEmailType,message,email) {
|
|||||||
email.attachments = [];
|
email.attachments = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import app from './hono/webs';
|
|||||||
import { email } from './email/email';
|
import { email } from './email/email';
|
||||||
import userService from './service/user-service';
|
import userService from './service/user-service';
|
||||||
import verifyRecordService from './service/verify-record-service';
|
import verifyRecordService from './service/verify-record-service';
|
||||||
|
import emailService from './service/email-service';
|
||||||
export default {
|
export default {
|
||||||
async fetch(req, env, ctx) {
|
async fetch(req, env, ctx) {
|
||||||
const url = new URL(req.url)
|
const url = new URL(req.url)
|
||||||
@@ -20,5 +21,6 @@ export default {
|
|||||||
async scheduled(c, env, ctx) {
|
async scheduled(c, env, ctx) {
|
||||||
await verifyRecordService.clearRecord({env})
|
await verifyRecordService.clearRecord({env})
|
||||||
await userService.resetDaySendCount({ env })
|
await userService.resetDaySendCount({ env })
|
||||||
|
await emailService.completeReceiveAll({ env })
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -489,7 +489,8 @@ const emailService = {
|
|||||||
.where(and(
|
.where(and(
|
||||||
inArray(email.userId, userIds),
|
inArray(email.userId, userIds),
|
||||||
eq(email.type, type),
|
eq(email.type, type),
|
||||||
eq(email.isDel, del)
|
eq(email.isDel, del),
|
||||||
|
ne(email.status, emailConst.status.SAVING),
|
||||||
))
|
))
|
||||||
.groupBy(email.userId);
|
.groupBy(email.userId);
|
||||||
return result;
|
return result;
|
||||||
@@ -611,6 +612,11 @@ const emailService = {
|
|||||||
}).where(eq(email.emailId, emailId)).returning().get();
|
}).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) {
|
async batchDelete(c, params) {
|
||||||
let { sendName, sendEmail, toEmail, subject, startTime, endTime, type } = params
|
let { sendName, sendEmail, toEmail, subject, startTime, endTime, type } = params
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user