Skip to content

Commit

Permalink
improve webmail
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed May 18, 2024
1 parent 01ed5ce commit 5bce05b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions application/static/webmail.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var g_prevPreviewId = false;

//从一个包含查询字符串的url里面提取某个查询参数,不存在返回空串
function GetUrlQueryParam(url, key) {
let params = '', value = '';
Expand All @@ -21,6 +23,8 @@ function FetchMailList() {

//使用字典列表填充网页的邮件列表
function PopulateMailList(mails) {
g_prevPreviewId = false;
$('#toggle_select_mail').prop('checked', false);
const $tbody = $('.mail-list-table tbody');
$tbody.empty();
if (mails && mails.length > 0) {
Expand All @@ -45,18 +49,24 @@ function PopulateMailList(mails) {
//index: all_mails列表的索引号
function DisplayMailPreview(index) {
const mail = all_mails[index];
const mailId = mail.id;
if (mailId === g_prevPreviewId) {
return;
}

const $mailPreview = $('#mailPreview');
$mailPreview.html('');
if (!mail) {
return;
}
MakeAjaxRequest("/webmail/content/" + mail.id, "GET", null, function (resp) {
MakeAjaxRequest(`/webmail/content/${mailId}`, "GET", null, function (resp) {
let content = `<div class="mail-preview-header"><h4>${mail.subject}</h4>
<strong>${i18n.from}:</strong> ${mail.sender}<br/>
<strong>${i18n.to}:</strong> ${mail.to}<br/>
<strong>${i18n.time}:</strong> ${mail.datetime}<br/></div>
<div class="mail-preview-content">${resp.content}</div>`;
$mailPreview.html(content);
g_prevPreviewId = mailId;
});
}

Expand Down Expand Up @@ -193,6 +203,8 @@ function DeleteMails(act) {
return;
}

$('#toggle_select_mail').prop('checked', false);

let ids = selectedMails.map(item=>item.mail.id);
let isUndelete = selectedMails.every(item=>item.mail.status=='deleted');
let url = isUndelete ? "/webmail/undelete" : "/webmail/delete";
Expand All @@ -202,7 +214,8 @@ function DeleteMails(act) {
item.mail.status = 'read';
});
} else {
selectedMails.forEach(item => {
//需要倒序遍历以避免索引问题
selectedMails.reverse().forEach(item => {
all_mails.splice(item.index, 1);
});
}
Expand Down
3 changes: 2 additions & 1 deletion application/view/inbound_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ def CollectSoupLinks(soup, forceToLinks):
#将接收到的邮件暂存到数据库
#暂时不支持保存附件
def SaveInEmailToDb(user, sender, to, subject, txtBodies, htmlBodies):
to = ', '.join(to) if isinstance(to, list) else str(to)
size = sum([len(item) for item in [*txtBodies, *htmlBodies]])
#GAE对json字段里面的子字段也有1500字节限制,所以这里只能转换为一个字符串
body = json.dumps({'txtBodies': txtBodies, 'htmlBodies': htmlBodies})
InBox.create(user=user.name, sender=sender, to=str(to), subject=subject, status='unread', size=size, body=body)
InBox.create(user=user.name, sender=sender, to=to, subject=subject, status='unread', size=size, body=body)

#webmail网页
@bpInBoundEmail.route("/webmail", endpoint='WebmailRoute')
Expand Down

0 comments on commit 5bce05b

Please sign in to comment.