diff --git a/entry/src/main/ets/pages/imap.ets b/entry/src/main/ets/pages/imap.ets index c76a90cafeb5913e30184dc1116c05dfb920e280..45bf6fe51a88e10a48ae6677ce83aaed571633f7 100644 --- a/entry/src/main/ets/pages/imap.ets +++ b/entry/src/main/ets/pages/imap.ets @@ -452,10 +452,16 @@ struct Imap { folder.open(Folder.READ_WRITE, () => { let msgs = folder.getMessages() console.info("delete msg----" + msgs.length) - msgs[this.deleteMsgIndex-1].setFlags([Flag.DELETED],true, (err) => { + msgs[this.deleteMsgIndex-1].setFlags([Flag.DELETED],true,async (err) => { if (!err) { - folder.expunge() - prompt.showToast({ message: "删除成功", duration: 2000 }) + try { + await folder.syncExpunge() + MailLogger.info('ohos_mail-- expunge success') + prompt.showToast({ message: "删除成功", duration: 2500 }) + } catch (err) { + MailLogger.info('ohos_mail-- expunge fail: ' + err) + prompt.showToast({ message: "删除失败" + err, duration: 2500 }) + } return } prompt.showToast({ message: "删除失败:" + err, duration: 2000 }) @@ -608,5 +614,4 @@ async function asyncTask(index, hostReceive, portReceive, from, authorizationCod }) ]); return ret; -} - +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/pop.ets b/entry/src/main/ets/pages/pop.ets index a8a7be0e591591f9d96fc945910416e84e21b272..01ab2bed4012e0d85da19886b5fc0a33fa3ce863 100644 --- a/entry/src/main/ets/pages/pop.ets +++ b/entry/src/main/ets/pages/pop.ets @@ -379,10 +379,16 @@ struct Pop { folder.open(Folder.READ_WRITE, () => { let msgs = folder.getMessages() console.info("delete msg----" + msgs.length) - msgs[this.deleteMsgIndex-1].setFlags([Flag.DELETED], true, (err) => { + msgs[this.deleteMsgIndex-1].setFlags([Flag.DELETED], true, async (err) => { if (!err) { - folder.expunge() - prompt.showToast({ message: "删除成功", duration: 2500 }) + try { + await folder.syncExpunge() + MailLogger.info('ohos_mail-- expunge success') + prompt.showToast({ message: "删除成功", duration: 2500 }) + } catch (err) { + MailLogger.info('ohos_mail-- expunge fail: ' + err) + prompt.showToast({ message: "删除失败" + err, duration: 2500 }) + } return } prompt.showToast({ message: "删除失败:" + err, duration: 2500 }) diff --git a/mail/src/main/ets/Util.ts b/mail/src/main/ets/Util.ts index 374e11fbd85125aa9e2477bdecf24f4406c7e321..6567ce0ad945429e3ac403a842d73a9ab6468084 100644 --- a/mail/src/main/ets/Util.ts +++ b/mail/src/main/ets/Util.ts @@ -1106,8 +1106,10 @@ export class Util { } else if (!!encoding && (encoding.toLowerCase().includes('bit') || encoding.toLowerCase().includes('binary'))) { content = result } else if (!!encoding && encoding.toLowerCase().includes('b')) { - // Base64 编码直接解码即可 - content = Util.decode(result); + // Base64 编码 + let textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }) + let temp = new Uint8Array(Util.decodeBase64(result, true).array); + content = textDecoder.decodeWithStream(temp, { stream: false }); } else { content = result } diff --git a/mail/src/main/ets/mail/Folder.ts b/mail/src/main/ets/mail/Folder.ts index 8cbed94bf4ca51f88fa49bc5a41aef43cced8b10..3827cc7d2ce1e5af20412beb257f2072b532c782 100644 --- a/mail/src/main/ets/mail/Folder.ts +++ b/mail/src/main/ets/mail/Folder.ts @@ -281,12 +281,13 @@ export class Folder { if (!this.isOpen() || !!!this.folderInfo) { return -1 } - - if (this.folderInfo.has(Constant.UNREAD_MESSAGE_COUNT)) { - return this.folderInfo.get(Constant.UNREAD_MESSAGE_COUNT) - } else { - return 0 + let unreadMessageCount = 0 + if (this.folderInfo.has(Constant.UNREAD_MESSAGE_COUNT) ) { + unreadMessageCount += this.folderInfo.get(Constant.UNREAD_MESSAGE_COUNT) + } else if(this.folderInfo.has(Constant.NEW_MESSAGE_COUNT)) { + unreadMessageCount += this.folderInfo.get(Constant.NEW_MESSAGE_COUNT) } + return unreadMessageCount } public getNewMessageCount(): number { diff --git a/mail/src/main/ets/mail/MimeMessage.ts b/mail/src/main/ets/mail/MimeMessage.ts index 786e50332f6aa85318abddb0eeb48459ee5df52f..b99768d4d00c511c92f973326d3ccb2f7fb8a845 100644 --- a/mail/src/main/ets/mail/MimeMessage.ts +++ b/mail/src/main/ets/mail/MimeMessage.ts @@ -46,7 +46,7 @@ export class MimeMessage { //附件 private attachmentBody: Array<AttachmentBody> = new Array<AttachmentBody>() //邮件内容 - private text: string + private text: string = ""; //Html private html: string //图片mimeType @@ -216,13 +216,15 @@ export class MimeMessage { + Constant.LINEFEED if (attachmentDatas.length == 0 && imgDatas.length == 0) { //正文 start - msg += "------=_NextPart_" + guid1 + Constant.LINEFEED - + "Content-Type: text/plain" + "; \tcharset=\"gb2312\"" - + Constant.LINEFEED - + "Content-Transfer-Encoding: base64" + Constant.LINEFEED - + Constant.LINEFEED - + Util.encode64(Util.strUnicode2Ansi(this.text)) + Constant.LINEFEED - + Constant.LINEFEED + if(!!this.text && this.text.trim() != ""){ + msg += "------=_NextPart_" + guid1 + Constant.LINEFEED + + "Content-Type: text/plain" + "; \tcharset=\"gb2312\"" + + Constant.LINEFEED + + "Content-Transfer-Encoding: base64" + Constant.LINEFEED + + Constant.LINEFEED + + Util.encode64(Util.strUnicode2Ansi(this.text)) + Constant.LINEFEED + + Constant.LINEFEED + } if (!!this.html) { msg += "------=_NextPart_" + guid1 + Constant.LINEFEED @@ -240,12 +242,14 @@ export class MimeMessage { + Constant.LINEFEED //正文 start - + "------=_NextPart_" + guid2 + Constant.LINEFEED - + "Content-Type: text/plain" + "; \tcharset=\"gb2312\"" + Constant.LINEFEED - + "Content-Transfer-Encoding: base64" + Constant.LINEFEED - + Constant.LINEFEED - + Util.encode64(Util.strUnicode2Ansi(this.text)) + Constant.LINEFEED - + Constant.LINEFEED + if(!!this.text && this.text.trim() != ""){ + + "------=_NextPart_" + guid2 + Constant.LINEFEED + + "Content-Type: text/plain" + "; \tcharset=\"gb2312\"" + Constant.LINEFEED + + "Content-Transfer-Encoding: base64" + Constant.LINEFEED + + Constant.LINEFEED + + Util.encode64(Util.strUnicode2Ansi(this.text)) + Constant.LINEFEED + + Constant.LINEFEED + } if (!!this.html) { msg += "------=_NextPart_" + guid2 + Constant.LINEFEED @@ -267,7 +271,7 @@ export class MimeMessage { let nextPart = "------=_NextPart_" + guid1 + Constant.LINEFEED + "Content-Type: " + mimeType + "; charset=gb2312" + Constant.LINEFEED + "Content-Transfer-Encoding: base64" + Constant.LINEFEED - + "Content-Disposition: attachment; filename=\"" + "=?gb2312?B?" + Util.encode64(Util.strUnicode2Ansi(this.imgInside[i].getFileName())) + "?=" + "\"" + Constant.LINEFEED + + "Content-Disposition: inline; filename=\"" + "=?gb2312?B?" + Util.encode64(Util.strUnicode2Ansi(this.imgInside[i].getFileName())) + "?=" + "\"" + Constant.LINEFEED + "Content-ID: <" + this.imgInside[i].getContentId() + ">" + Constant.LINEFEED + Constant.LINEFEED diff --git a/mail/src/main/ets/mail/SocketUtil.ts b/mail/src/main/ets/mail/SocketUtil.ts index 88df18143afc9f1f1531e812d597e64e8bed059e..03053e8df2eb0548a0421787a692555252a7ca6a 100644 --- a/mail/src/main/ets/mail/SocketUtil.ts +++ b/mail/src/main/ets/mail/SocketUtil.ts @@ -34,6 +34,7 @@ export class SocketUtil { } public static connect(tcp, host: string, port: number, isSSL: boolean, ca: string[], timeout: number, connectEvent, responseEvent?) { + MailLogger.info("ohos_mail-- version flag:1.1.11") let ipInfo = wifiManager.getIpInfo() let ip = Util.intToIP(ipInfo.ipAddress) diff --git a/mail/src/main/ets/mail/Store.ts b/mail/src/main/ets/mail/Store.ts index 20adbf2812ddab022ca53969f2b4396d880caa41..b0d27f71d9aa1f3091f1975985ebba2f608f18de 100644 --- a/mail/src/main/ets/mail/Store.ts +++ b/mail/src/main/ets/mail/Store.ts @@ -748,7 +748,7 @@ export class Store { clearTimeout(this.timerId) } this.timerId = setTimeout(() => { - this.pop3Event(false, "send USER timeout") + this.pop3Event("send USER timeout") }, this.timeOutMillisecond) MailLogger.info('ohos_mail-- send user success'); }).catch(err => { @@ -1724,7 +1724,7 @@ export class Store { break case "USER": case "PASS": - this.pop3Event(false, "pop3 auth response timeout") + this.pop3Event("pop3 auth response timeout") break case "STAT": this.infoEvent(false, "pop3 STAT response timeout") diff --git a/mail/src/main/ets/mail/TransPort.ts b/mail/src/main/ets/mail/TransPort.ts index 8f965f27d56fc7af57318e4a925f1bdd83203f92..ed70088be513f31be4c2515c84abd5c1cdf8d6d4 100644 --- a/mail/src/main/ets/mail/TransPort.ts +++ b/mail/src/main/ets/mail/TransPort.ts @@ -23,7 +23,6 @@ import { SocketUtil } from './SocketUtil'; import net_socket from '@ohos.net.socket'; - /** * 发送邮件 */ @@ -39,6 +38,8 @@ export class TransPort { private expectCode = "220" private serverIsReady = false private isConnect = false + private timeOutMillisecond: number + private timerId = -1 /** * 设置连接服务器超时时长 @@ -57,6 +58,7 @@ export class TransPort { loginEvent(false, 'properties is null') return } + this.timeOutMillisecond = properties.getTimeOutMillisecond() this.properties = properties this.host = this.properties.getHost() let port = this.properties.getPort() @@ -90,8 +92,12 @@ export class TransPort { this.login() return } else if (asciiToStr.startsWith(this.expectCode)) { + if (this.timerId != -1) { + MailLogger.info("ohos_mail OK clear request timeout") + clearTimeout(this.timerId) + } if (this.expectCode.startsWith("221")) { -// socket.off('message'); + //socket.off('message'); this.closeEvent() this.serverIsReady = false this.isConnect = false @@ -113,6 +119,10 @@ export class TransPort { loginEvent(true, '') } } else { + if (this.timerId != -1) { + MailLogger.info("ohos_mail ERR clear request timeout") + clearTimeout(this.timerId) + } this.authenticationEvent(asciiToStr) if (this.isConnect) { this.sendMessageEvent(asciiToStr) @@ -136,6 +146,8 @@ export class TransPort { resolve("") return } + MailLogger.info('ohos_mail-- ehlo err:' + err); + reject(err) }, "250") }).then((result) => { return new Promise((resolve, reject) => { @@ -144,6 +156,8 @@ export class TransPort { resolve("") return } + MailLogger.info('ohos_mail-- auth err:' + err); + reject(err) }, "334") }) }).then((result) => { @@ -153,6 +167,8 @@ export class TransPort { resolve("") return } + MailLogger.info('ohos_mail-- user err:' + err); + reject(err) }, "334") }) @@ -163,6 +179,8 @@ export class TransPort { resolve("") return } + MailLogger.info('ohos_mail-- password err:' + err); + reject(err) }, "235") }) }) @@ -180,6 +198,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("ehlo response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send EHLO success '); }).catch(err => { @@ -199,6 +223,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("AUTH LOGIN response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send AUTH LOGIN success'); }).catch(err => { @@ -218,6 +248,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("user response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send user success'); }).catch(err => { @@ -237,6 +273,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("pass response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send pass success'); }).catch(err => { @@ -255,14 +297,22 @@ export class TransPort { this.sendFrom(mimeMessage, (err) => { if (!err) { resolve("") + return } + MailLogger.info('ohos_mail-- from err:' + err); + event(err) + reject(err) }, "250") }).then((result) => { return new Promise((resolve, reject) => { this.sendRCPTs(mimeMessage, (err) => { if (!err) { resolve("") + return } + MailLogger.info('ohos_mail-- rcpts err:' + err); + event(err) + reject(err) }) }) }).then((result) => { @@ -270,7 +320,11 @@ export class TransPort { this.sendDATA((err) => { if (!err) { resolve("") + return } + MailLogger.info('ohos_mail-- data err:' + err); + event(err) + reject(err) }, "354") }) }).then((result) => { @@ -279,7 +333,11 @@ export class TransPort { if (!err) { this.sendMessageEvent() resolve("") + return } + MailLogger.info('ohos_mail-- msg data err:' + err); + event(err) + reject(err) }, "250") }) }) @@ -293,6 +351,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("MAIL FROM response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send MAIL FROM success'); }).catch(err => { @@ -307,6 +371,10 @@ export class TransPort { this.sendRCPT(recipients[i], (err) => { if (!err) { resolve("") + } else { + reject(err) + event(err) + return } }, "250") }) @@ -314,7 +382,6 @@ export class TransPort { event(null) } - private sendRCPT(address, event: (err?) => void, expectCode) { this.authenticationEvent = event let cmd = this.isSSL ? "RCPT TO:<" + address + ">" + Constant.LINEFEED : @@ -322,6 +389,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("RCPT response timeout : " + address) + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send RCPT success'); }).catch(err => { @@ -337,6 +410,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("DATA response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send DATA success'); }).catch(err => { @@ -356,6 +435,12 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.authenticationEvent("msg body response timeout") + }, this.timeOutMillisecond) this.expectCode = expectCode MailLogger.info('ohos_mail-- send msg body success'); }).catch(err => { @@ -374,6 +459,13 @@ export class TransPort { encoding: "UTF-8" } this.socket.send(cmd).then(() => { + if (this.timerId != -1) { + clearTimeout(this.timerId) + } + this.timerId = setTimeout(() => { + this.closeEvent("quit response timeout") + this.socket.close() + }, this.timeOutMillisecond) this.expectCode = "221" MailLogger.info('ohos_mail-- send quit success'); }).catch(err => {