diff --git a/README.md b/README.md index 7af0bd6a9f3d430880bb6de0556deba49962ebaf..58d14ae246ebbd98d240ebce30749f6d1614ed87 100644 --- a/README.md +++ b/README.md @@ -1,1282 +1,1279 @@ # mail -## 简介 +## Introduction -> ohos_mail主要提供电子邮件SMTP、POP3、IMAP协议的发送、接收、移动、删除等功能,能够解析和构建eml格式的电子邮件,识别电子邮件的MIME类型消息头和消息体,方便开发者执行一些常用的邮件传输。 -> 其中本软件/mail/src/main/ets/mail/目录下的代码是开源软件 [mail](https://github.com/eclipse-ee4j/mail) 的TypeScript语言实现; -> 以及本软件/mail/src/main/ets/mime_types/目录下的代码是开源软件 [mime-types](https://github.com/overview/mime-types) 的TypeScript语言实现。 +> ohos_mail provides features such as sending, receiving, moving, and deleting emails in accordance with the SMTP, POP3, and IMAP protocols. It can parse and construct emails in EML format and identify MIME message headers and bodies of emails. +> The code in the `/mail/src/main/ets/mail/` directory is the implementation of the open source software [mail](https://github.com/eclipse-ee4j/mail) using TypeScript. +> The code in the `/mail/src/main/ets/mime_types/` directory is the implementation of the open source software [mime-types](https://github.com/overview/mime-types) using TypeScript. -![log.gif](image/sample.gif) - -## 下载安装 +## How to Install ```shell ohpm install @ohos/mail ``` -OpenHarmony ohpm环境配置等更多内容,请参考 [如何安装OpenHarmony ohpm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) 。 +For details about the OpenHarmony ohpm environment configuration, see [OpenHarmony HAR](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.en.md). -## 测试资源使用注意事项 +## Precautions for Using Test Resources -内置的测试资源文件放在./testFile目录下,通过git lfs的方式上传的,如果直接下载项目的zip包,得到的资源文件只是一个快捷方式,需要进资源文件目录手动下载。或者通过git clone的方式下载代码,这样得到的资源文件是完整的。 +The test resource files are uploaded to the `./testFile` directory in git lfs mode. If you directly download the .zip package of the project, only the shortcuts of the resource files are obtained. You need to manually download the files from the resource file directory. Alternatively, download the code in git clone mode. In this way, the obtained resource files are complete. -## 使用说明 +## How to Use -#### 使用前在demo或者XTS中的xx改为正确的邮箱账号和授权码,才可正常的使用demo。 +#### Before using the demo, change *xx* in the demo or XTS to the correct email account and authorization code. -1、引入依赖 +1. Import the dependency. - ``` - import { MimeTypeDetector,EmlFormat,Store,Attachment } from '@ohos/mail'; - ``` + ``` + import { MimeTypeDetector,EmlFormat,Store,Attachment } from '@ohos/mail'; + ``` -2、在module.json5中添加权限 +2. Add permissions in the `module.json5` file. - ``` - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - }, - { - "name": "ohos.permission.GET_NETWORK_INFO" - }, - { - "name": "ohos.permission.GET_WIFI_INFO" - } - ] - ``` + ``` + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.GET_NETWORK_INFO" + }, + { + "name": "ohos.permission.GET_WIFI_INFO" + } + ] + ``` -3、在EntryAbility初始化MimeTypeDetector +3. Initialize `MimeTypeDetector` in the EntryAbility. - ``` - onWindowStageCreate(windowStage) { - MimeTypeDetector.init((data)=>{ - GlobalContext.getContext().setValue("cacheContent", data); - }) - } - ``` - -4、文件Mime类型解析 - - ``` - //解析文件的MimeType - let mimetype =MimeTypeDetector.detectMimeType(path + "/logdemo.bat") - console.log('sample mimetype detectMimeType bat:' + mimetype); - ``` - -5、邮件解析 - - ``` - //解析邮件文件 - let filePath = path + '/sample.eml' - new EmlFormat().parse(filePath, function (error, result) { - console.info('result-------' + JSON.stringify(result)) - }); - - //解析string类型的邮件内容 - let content="' - EmlFormat.parseString(content, (error, msg: Message) => { - //获取邮件各种详细信息 - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getFrom()[0])) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getSubject())) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getRecipients(RecipientType.TO))) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getText())) - MailLogger.info('ohos_test-- html--' + JSON.stringify(result.getHtml())) - MailLogger.info('ohos_test-- file--' + JSON.stringify(result.getFiles())) - ... - }); - ``` - -6、构建邮件 - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject("") - mimeMessage.setMIMEVersion("1.0") - - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - //设置纯文本格式的正文 - mimeMessage.setText("test") - //设置html格式文件 - // mimeMessage.setHtml("" + "
" + text + "
") - //设置html格式文件带图片 - let contentId = "imag01" - mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId)) - let contentId1 = "imag02" - mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId1)) - mimeMessage.setHtml("" - + "
" + this.text - + "" - + "" - + "

") - - //设置附件 - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) - let buildResult:string = mimeMessage.getMimeMessage() - ``` - -7、设置读取邮箱的协议(支持IMAP和POP3协议) - - ``` - //设置imap协议 - let properties = new Properties("imap") - //设置imap服务器地址 - properties.setHost("imap.qq.com") - //设置imap服务器端口 - properties.setPort(143) - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - //设置pop3协议 - let properties = new Properties("pop3") - //设置pop3服务器地址 - properties.setHost("pop.qq.com") - //设置pop3服务器端口 - properties.setPort(110) - ``` - -8、发送邮件 - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let properties = new Properties() - properties.setFrom(this.from) - properties.setHost(this.host) - properties.setPort(this.port) - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - properties.setAuthorizationCode(this.authorizationCode) - this.transport = new TransPort() - //连接服务 - this.transport.connect(properties, (success:boolean, err:Error) =>{ - if (success) { - MailLogger.info('ohos_mail-- login smtp success:') - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject("") - mimeMessage.setMIMEVersion("1.0") - - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - //设置纯文本格式的正文 - mimeMessage.setText("") - //设置html格式文件 - // mimeMessage.setHtml("" + "
" + text + "
") - //设置html格式文件带图片 - let contentId = "imag01" - mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId)) - let contentId1 = "imag02" - mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId1)) - mimeMessage.setHtml("" - + "
" + this.text - + "" - + "" - + "

") - - //设置附件 - let attachment1=new AttachmentBody(path, "test.txt") - //如果是在taskpool中使用需要调用下面方法将GlobalContext.getContext().getValue('cacheContent')传递进去,反之可以不用调 - //attachment1.setCacheContent(GlobalContext.getContext().getValue('cacheContent')) - mimeMessage.addAttachmentBody(attachment1) - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.docx")) - //发送邮件 - this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) =>{ - if (success) { - MailLogger.info('ohos_mail-- send mail success!'); - prompt.showToast({message:"发送成功!", duration:4000}) - } else { - prompt.showToast({message:"发送失败:" + JSON.stringify(err), duration:4000}) - } - //关闭连接 - this.transport.close((err:Error) => { - if (!err) { - MailLogger.info('ohos_mail-- socket close success!'); - } else { - MailLogger.info('ohos_mail-- socket close fail:' + err); - } - }) + ``` + onWindowStageCreate(windowStage) { + MimeTypeDetector.init((data)=>{ + GlobalContext.getContext().setValue("cacheContent", data); + }) + } + ``` + +4. Parse the MIME type of a file. + + ``` + // Parse the MIME type of a file. + let mimetype =MimeTypeDetector.detectMimeType(path + "/logdemo.bat") + console.log('sample mimetype detectMimeType bat:' + mimetype); + ``` + +5. Parse an email. + + ``` + // Parse an email. + let filePath = path + '/sample.eml' + new EmlFormat().parse(filePath, function (error, result) { + console.info('result-------' + JSON.stringify(result)) + }); + + // Parse the email content of the string type. + let content="' + EmlFormat.parseString(content, (error, msg: Message) => { + // Obtain the detailed information about the email. + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getFrom()[0])) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getSubject())) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getRecipients(RecipientType.TO))) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getText())) + MailLogger.info('ohos_test-- html--' + JSON.stringify(result.getHtml())) + MailLogger.info('ohos_test-- file--' + JSON.stringify(result.getFiles())) + ... + }); + ``` + +6. Construct an email. + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject("") + mimeMessage.setMIMEVersion("1.0") + + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + // Set the body in plain text format. + mimeMessage.setText("test") + // Set an HTML file. + // mimeMessage.setHtml("" + "
" + text + "
") + // Set an HTML file with an image. + let contentId = "imag01" + mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId)) + let contentId1 = "imag02" + mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId1)) + mimeMessage.setHtml("" + + "
" + this.text + + "" + + "" + + "

") + + // Set an attachment. + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) + let buildResult:string = mimeMessage.getMimeMessage() + ``` + +7. Set the protocol for reading the email. (IMAP and POP3 are supported.) + + ``` + // Set the IMAP protocol. + let properties = new Properties("imap") + // Set the address of the IMAP server. + properties.setHost("imap.qq.com") + // Set the port number of the IMAP server. + properties.setPort(143) + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. + properties.ca(this.ca) + // Set the POP3 protocol. + let properties = new Properties("pop3") + // Set the address of the POP3 server. + properties.setHost("pop.qq.com") + // Set the port number of the POP3 server. + properties.setPort(110) + ``` + +8. Send an email. + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let properties = new Properties() + properties.setFrom(this.from) + properties.setHost(this.host) + properties.setPort(this.port) + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. + properties.ca(this.ca) + properties.setAuthorizationCode(this.authorizationCode) + this.transport = new TransPort() + // Connect to the service. + this.transport.connect(properties, (success:boolean, err:Error) =>{ + if (success) { + MailLogger.info('ohos_mail-- login smtp success:') + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject("") + mimeMessage.setMIMEVersion("1.0") + + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + // Set the body in plain text format. + mimeMessage.setText("") + // Set an HTML file. + // mimeMessage.setHtml("" + "
" + text + "
") + // Set an HTML file with an image. + let contentId = "imag01" + mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId)) + let contentId1 = "imag02" + mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId1)) + mimeMessage.setHtml("" + + "
" + this.text + + "" + + "" + + "

") + + // Set an attachment. + let attachment1=new AttachmentBody(path, "test.txt") + // Call the following method to pass in GlobalContext.getContext().getValue('cacheContent') only if the function is used in the TaskPool. + //attachment1.setCacheContent(GlobalContext.getContext().getValue('cacheContent')) + mimeMessage.addAttachmentBody(attachment1) + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.docx")) + // Send the email. + this.transport.sendMessage(mimeMessage, (success: boolean, err:Error) =>{ + if (success) { + MailLogger.info('ohos_mail-- send mail success!'); + prompt.showToast({message:"Sent successfully.", duration:4000}) + } else { + prompt.showToast({message:"Sending failed: "+ JSON.stringify(err), duration:4000}) + } + // Close the connection. + this.transport.close((err:Error) => { + if (!err) { + MailLogger.info('ohos_mail-- socket close success!'); + } else { + MailLogger.info('ohos_mail-- socket close fail:' + err); + } + }) + }) + + } else { + prompt.showToast({message:JSON.stringify(err), duration:4000}) + MailLogger.error('ohos_mail-- login smtp fail:' + err); + } + }); + ``` + +9. Receive an email (IMAP). + + ``` + let properties = new Properties("imap") + properties.setHost(this.hostReceive) + properties.setPort(this.portReceive) + properties.setFrom(this.from) + properties.setAuthorizationCode(this.authorizationCode) + properties.ssl(this.isSSL) + if (this.isSSL) { + properties.ca(this.ca) + } + let map::Map = new Map() + map.set("name", "myname"); + map.set("version", "1.0.0"); + map.set("vendor", "myclient"); + map.set("support-email", "xx@test.com"); + + let store = new Store(properties) + if (this.hostReceive.includes("126") || this.hostReceive.includes("163") + || this.hostReceive.includes("yeah")) { + store.id(map) + } + store.connect(async (success: boolean, err:Error) => { + if (success) { + // Obtain the folder list. + store.getDefaultFolder().list((success:boolean, folders:Folder) => { + if (success) { + for (let i = 0; i < folders.length; i++) { + MailLogger.info("ohos_mail folder list----"+folders[i].getName()) + } + } + }) + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async (err:Error) => { + if (!err) { + let messages = folder.getMessages() + if (messages.length > 0 && messages.length >= this.readMsgIndex) { + let msg = messages[this.readMsgIndex-1] + msg.getAllHeaders(async (success:boolean, msg: Message) => { + if (success) { + this.parseResult += 'Headers ' + '\r\n' + + 'From:' + msg.getFrom()[0] + "\r\n" + + 'To:' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" + + 'Subject:' + msg.getSubject() + "\r\n" + + 'Date: ' + msg.getSentDate () + + "\r\n------------------------------------\r\n\r\n" + } + + try { + let result = await msg.syncGetContent() + let mime = result as MimeMultipart + + try { + let textBody = await mime.syncGetText() + this.parseResult += 'Body' + '\r\n' + + 'Data: ' + textBody.getContent() + "\r\n" + + 'CharSet: ' + textBody.getCharSet() + "\r\n" + + 'MimeType: ' + textBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + textBody.getTransferEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getText fail:' + err) + } + + try { + let htmlBody = await mime.syncGetHtml() + this.parseResult += 'Html ' + '\r\n' + + 'Data: ' + htmlBody.getContent() + "\r\n" + + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" + + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + htmlBody.getTransferEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getHtml fail:' + err) + } + + let attachCount = mime.getAttachmentSize() + for (let i = 0; i < attachCount; i++) { + try { + let attachBody = await mime.syncGetAttachment(i) + this.parseResult += 'Attachment' + i + '\r\n' + + 'FileName: ' + attachBody.getFileName() + "\r\n" + + 'Data: ' + attachBody.getContent() + "\r\n" + + 'CharSet: ' + attachBody.getCharSet() + "\r\n" + + 'MimeType: ' + attachBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + attachBody.getEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getAttachment fail:' + err) + } + } + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getContent fail:' + err) + } + }) + } + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- open folder fail : ' + err) + return + } }) - - } else { - prompt.showToast({message:JSON.stringify(err), duration:4000}) - MailLogger.error('ohos_mail-- login smtp fail:' + err); + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` + +10. Receive an email (POP3). + + ``` + let properties = new Properties("pop3") + properties.setHost(this.hostReceive) + properties.setPort(this.portReceive) + properties.setFrom(this.from) + properties.setAuthorizationCode(this.authorizationCode) + properties.ssl(this.isSSL) + if (this.isSSL) { + properties.ca(this.ca) } - }); - ``` - -9、接收邮件(imap) - - ``` - let properties = new Properties("imap") - properties.setHost(this.hostReceive) - properties.setPort(this.portReceive) - properties.setFrom(this.from) - properties.setAuthorizationCode(this.authorizationCode) - properties.ssl(this.isSSL) - if (this.isSSL) { - properties.ca(this.ca) - } - let map::Map = new Map() - map.set("name", "myname"); - map.set("version", "1.0.0"); - map.set("vendor", "myclient"); - map.set("support-email", "xx@test.com"); - - let store = new Store(properties) - if (this.hostReceive.includes("126") || this.hostReceive.includes("163") - || this.hostReceive.includes("yeah")) { - store.id(map) - } - store.connect(async (success: boolean, err:Error) => { - if (success) { - //获取文件夹列表 - store.getDefaultFolder().list((success:boolean, folders:Folder) => { - if (success) { - for (let i = 0; i < folders.length; i++) { - MailLogger.info("ohos_mail folder list----"+folders[i].getName()) - } - } - }) - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async (err:Error) => { - if (!err) { + + let store = new Store(properties) + store.connect((success:boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async (err:Error) => { let messages = folder.getMessages() if (messages.length > 0 && messages.length >= this.readMsgIndex) { let msg = messages[this.readMsgIndex-1] - msg.getAllHeaders(async (success:boolean, msg: Message) => { - if (success) { - this.parseResult += 'Headers ' + '\r\n' - + '发件人: ' + msg.getFrom()[0] + "\r\n" - + '收件人: ' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" - + '主题: ' + msg.getSubject() + "\r\n" - + '日期: ' + msg.getSentDate() - + "\r\n------------------------------------\r\n\r\n" - } - - try { - let result = await msg.syncGetContent() - let mime = result as MimeMultipart - - try { - let textBody = await mime.syncGetText() - this.parseResult += '正文 ' + '\r\n' - + 'Data: ' + textBody.getContent() + "\r\n" - + 'CharSet: ' + textBody.getCharSet() + "\r\n" - + 'MimeType: ' + textBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + textBody.getTransferEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getText fail:' + err) - } - - try { - let htmlBody = await mime.syncGetHtml() - this.parseResult += 'Html ' + '\r\n' - + 'Data: ' + htmlBody.getContent() + "\r\n" - + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" - + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + htmlBody.getTransferEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getHtml fail:' + err) - } - - let attachCount = mime.getAttachmentSize() - for (let i = 0; i < attachCount; i++) { - try { - let attachBody = await mime.syncGetAttachment(i) - this.parseResult += '附件 ' + i + '\r\n' - + 'FileName: ' + attachBody.getFileName() + "\r\n" - + 'Data: ' + attachBody.getContent() + "\r\n" - + 'CharSet: ' + attachBody.getCharSet() + "\r\n" - + 'MimeType: ' + attachBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + attachBody.getEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getAttachment fail:' + err) - } + // Obtain the parsed email content. + try { + let message = await msg.syncGetContent() + let result = message as Message + this.parseResult = 'From:' + result.getFrom()[0] + "\r\n\r\n" + + 'Subject:' + result.getSubject() + "\r\n\r\n" + + 'To:' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" + + 'Body:' + result.getText() + "\r\n\r\n" + + 'HTML: ' + result.getHtml() + "\r\n\r\n" + + let files = result.getFiles() + if (!!files) { + let length = files.length + for (let i = 0; i < length; i++) { + this.parseResult += "Attachment" + (i + 1) +": " + files[i].getFileName() + "\r\n" + + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n" + + " Content-Type:" + files[i].getMimeType() + "\r\n" + + " Attachment content: " + files[i].getData() + "\r\n" } - - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- close imap success') - } else { - MailLogger.info('ohos_mail-- close imap fail') - } - }) - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getContent fail:' + err) } - }) + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + } catch (e) { + MailLogger.info('ohos_mail-- sync getContent fail:' + err) + } } + }) } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- open folder fail : ' + err) - return + prompt.showToast({ message: JSON.stringify(err), duration: 2500 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) } - }) + }) + ``` + +11. Delete an email. + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom("xxx@qq.com") + properties.setAuthorizationCode("xx") + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. + properties.ca(this.ca) + let store = new Store(properties) + store.connect(async (success: boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, () => { + let msgs = folder.getMessages() + msgs[this.deleteMsgIndex-1].setFlag(Flag.DELETED, (success, result) => { + if (success) { + folder.expunge() + } + }) + }) } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) } - }) - ``` - -10、接收邮件(pop3) - - ``` - let properties = new Properties("pop3") - properties.setHost(this.hostReceive) - properties.setPort(this.portReceive) - properties.setFrom(this.from) - properties.setAuthorizationCode(this.authorizationCode) - properties.ssl(this.isSSL) - if (this.isSSL) { + }) + ``` + +12. Move an email. + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. properties.ca(this.ca) - } - - let store = new Store(properties) - store.connect((success:boolean, err:Error) => { - if (success) { + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + // Obtain an INBOX object. let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async (err:Error) => { + // Open the inbox. + folder.open(Folder.READ_WRITE, async () => { + // Obtain all emails in the mailbox. + let messages = folder.getMessages() + folder.moveMessages([messages[0]], new Folder('Sent Messages'),(success,err)=>{ + if(success){ + MailLogger.info('ohos_mail-- moveMessages success') + }else{ + MailLogger.info('ohos_mail-- moveMessages fail : ' + err) + } + }) + + // Some mailboxes do not support the move function. You can use the following method to implement move: + folder.copyMessages([messages[0]], new Folder('Drafts'), (success, err) => { + if (success) { + MailLogger.info('ohos_mail-- copyMessages success') + } else { + MailLogger.info('ohos_mail-- copyMessages fail : ' + err) + } + messages[0].setFlag(Flag.DELETED, (err:Error) => { + if (!err) { + MailLogger.info('ohos_mail-- set flag success') + } else { + MailLogger.info('ohos_mail-- set flag fail') + } + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- set flag close success') + } else { + MailLogger.info('ohos_mail-- set flag close fail') + } + }) + }) + }) + }) + ``` + +13. Forward or reply to an email. + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort("143") + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. + properties.ca(this.ca) + let store = new Store(properties) + store.connect((success:boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async () => { let messages = folder.getMessages() - if (messages.length > 0 && messages.length >= this.readMsgIndex) { - let msg = messages[this.readMsgIndex-1] - //获取解析后的邮件内容 - try { - let message = await msg.syncGetContent() - let result = message as Message - this.parseResult = '发件人: ' + result.getFrom()[0] + "\r\n\r\n" - + '主题: ' + result.getSubject() + "\r\n\r\n" - + '收件人: ' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" - + '正文: ' + result.getText() + "\r\n\r\n" - + 'HTML: ' + result.getHtml() + "\r\n\r\n" - - let files = result.getFiles() - if (!!files) { - let length = files.length - for (let i = 0; i < length; i++) { - this.parseResult += "附件 " + (i + 1) + ": " + files[i].getFileName() + "\r\n" - + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n" - + " Content-Type:" + files[i].getMimeType() + "\r\n" - + " 附件内容:" + files[i].getData() + "\r\n" - } + messages[0].getContent((success, message: Message) => { + let properties = new Properties() + properties.setFrom(this.from) + properties.setHost("smtp.qq.com") + properties.setPort(25) + properties.setAuthorizationCode("xx") + this.transport = new TransPort() + // Connect to the service. + this.transport.connect(properties, (success:boolean, err:Error) => { + if (success) { + MailLogger.info('ohos_mail-- login smtp success:'); + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject ("Forward:"+ message.getSubject ()) + + let text = "Forward Test\r\n\r\n\r\n" + + "------------------ Original email ------------------\r\n" + + "From: " + message.getFrom()[0] + "\r\n" + + "Sent at: " + message.getSentDate() + "\r\n" + let to = message.getRecipients(RecipientType.TO) + if (!!to) { + text += "To:" + for (let i = 0; i < to.length; i++) { + if (i != to.length - 1) { + text += to[i] + " , " + } else { + text += to[i] + "\r\n" + } } - - store.close((success:boolean) => { + } + + text += "Subject: " + message.getSubject() + "\r\n" + let cc = message.getRecipients(RecipientType.CC) + if (!!cc) { + text += "Cc:" + for (let i = 0; i < cc.length; i++) { + if (i != cc.length - 1) { + text += cc[i] + " , " + } else { + text += cc[i] + "\r\n" + } + } + } + +"\r\n\r\n" + + message.getText() + // Set the body in plain text format. + mimeMessage.setText(text) + // Set an HTML file. + mimeMessage.setHtml(message.getHtml()) + let files = message.getFiles() + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + if (!!files) { + for (let i = 0;i < files.length; i++) { + let file = files[i] + if (!!file.getContentID()) { + var mimeBody = new MimeBodyPart(path, file.getFileName(), file.getContentID()) + mimeBody.setDta(file.getUint8ArrayData()) + mimeBody.setMimeType(file.getMimeType()) + mimeMessage.addImgInside(mimeBody) + } else { + mimeMessage.addAttachmentBody(file) + } + } + } + // Forward the email. + this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) => { if (success) { - MailLogger.info('ohos_mail-- close imap success') + MailLogger.info('ohos_mail-- send message success'); + prompt.showToast({ message: "Forwarded successfully.", duration: 4000 }) } else { - MailLogger.info('ohos_mail-- close imap fail') + prompt.showToast({ message:"Forwarding failed: "+ JSON.stringify(err), duration: 4000 }) } - }) - } catch (e) { - MailLogger.info('ohos_mail-- sync getContent fail:' + err) + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login smtp fail:' + err); } - } + }); + }) }) } else { - prompt.showToast({ message: JSON.stringify(err), duration: 2500 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err); } - }) - ``` - -11、删除邮件 - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom("xxx@qq.com") - properties.setAuthorizationCode("xx") - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success: boolean, err:Error) => { - if (success) { - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, () => { - let msgs = folder.getMessages() - msgs[this.deleteMsgIndex-1].setFlag(Flag.DELETED, (success, result) => { - if (success) { - folder.expunge() - } - }) }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` - -12、移动邮件 - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - //获取INBOX邮箱对象(收件箱) - let folder: Folder = store.getFolder("INBOX") - //打开INBOX邮箱 - folder.open(Folder.READ_WRITE, async () => { - //获取当前邮箱的所有邮件 - let messages = folder.getMessages() - folder.moveMessages([messages[0]], new Folder('Sent Messages'),(success,err)=>{ - if(success){ - MailLogger.info('ohos_mail-- moveMessages success') - }else{ - MailLogger.info('ohos_mail-- moveMessages fail : ' + err) - } - }) - - //部分邮箱不支持MOVE 可以使用以下方式实现MOVE功能 - folder.copyMessages([messages[0]], new Folder('草稿箱'), (success, err) => { - if (success) { - MailLogger.info('ohos_mail-- copyMessages success') - } else { - MailLogger.info('ohos_mail-- copyMessages fail : ' + err) - } - messages[0].setFlag(Flag.DELETED, (err:Error) => { - if (!err) { - MailLogger.info('ohos_mail-- set flag success') - } else { - MailLogger.info('ohos_mail-- set flag fail') - } - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- set flag close success') - } else { - MailLogger.info('ohos_mail-- set flag close fail') - } - }) - }) - }) - }) - ``` - -13、转发/回复 邮件 - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort("143") - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - let store = new Store(properties) - store.connect((success:boolean, err:Error) => { - if (success) { - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async () => { - let messages = folder.getMessages() - messages[0].getContent((success, message: Message) => { - let properties = new Properties() - properties.setFrom(this.from) - properties.setHost("smtp.qq.com") - properties.setPort(25) - properties.setAuthorizationCode("xx") - this.transport = new TransPort() - //连接服务 - this.transport.connect(properties, (success:boolean, err:Error) => { - if (success) { - MailLogger.info('ohos_mail-- login smtp success:'); - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject("转发:" + message.getSubject()) - - let text = "转发测试\r\n\r\n\r\n" - + "------------------ 原始邮件 ------------------\r\n" - + "发件人: " + message.getFrom()[0] + "\r\n" - + "发送时间: " + message.getSentDate() + "\r\n" - let to = message.getRecipients(RecipientType.TO) - if (!!to) { - text += "收件人: " - for (let i = 0; i < to.length; i++) { - if (i != to.length - 1) { - text += to[i] + " , " - } else { - text += to[i] + "\r\n" - } - } - } - - text += "主题: " + message.getSubject() + "\r\n" - let cc = message.getRecipients(RecipientType.CC) - if (!!cc) { - text += "抄送: " - for (let i = 0; i < cc.length; i++) { - if (i != cc.length - 1) { - text += cc[i] + " , " - } else { - text += cc[i] + "\r\n" - } + ``` + +14. Manage the mailbox. + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(25) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + // Set whether to use SSL. + properties.ssl(true) + // Set the CA certificate. + properties.ca(this.ca) + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + // Create a mailbox (folder). + store.createFolder("Test", (success, err) =>{ + if (success) { + console.info('ohos_mail-- create mail success') + } else { + console.info('ohos_mail-- create mail fail:' + err) } - } - +"\r\n\r\n" - + message.getText() - //设置纯文本格式的正文 - mimeMessage.setText(text) - //设置html - mimeMessage.setHtml(message.getHtml()) - let files = message.getFiles() - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - if (!!files) { - for (let i = 0;i < files.length; i++) { - let file = files[i] - if (!!file.getContentID()) { - var mimeBody = new MimeBodyPart(path, file.getFileName(), file.getContentID()) - mimeBody.setDta(file.getUint8ArrayData()) - mimeBody.setMimeType(file.getMimeType()) - mimeMessage.addImgInside(mimeBody) - } else { - mimeMessage.addAttachmentBody(file) - } + }) + + // Rename a mailbox (folder). + store.renameFolder("Test", "TestMail", (success, err) =>{ + if (success) { + console.info('ohos_mail-- rename mail success') + } else { + console.info('ohos_mail-- rename mail fail:' + err) } - } - //转发邮件 - this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) => { + }) + + // Delete a mailbox (folder). + store.deleteFolder("TestMail", (success, err) =>{ if (success) { - MailLogger.info('ohos_mail-- send message success'); - prompt.showToast({ message: "转发成功!", duration: 4000 }) + console.info('ohos_mail-- delete mail success') } else { - prompt.showToast({ message: "转发失败:" + JSON.stringify(err), duration: 4000 }) + console.info('ohos_mail-- delete mail fail:' + err) } - - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- close imap success') - } else { - MailLogger.info('ohos_mail-- close imap fail') - } - }) - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login smtp fail:' + err); - } - }); - }) - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err); - } - }) - ``` - -14、邮箱管理 - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(25) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - //设置是否使用ssl - properties.ssl(true) - //设置ca证书 - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - //创建邮箱(文件夹) - store.createFolder("Test", (success, err) =>{ - if (success) { - console.info('ohos_mail-- create mail success') - } else { - console.info('ohos_mail-- create mail fail:' + err) - } - }) - - //重命名邮箱(文件夹) - store.renameFolder("Test", "TestMail", (success, err) =>{ - if (success) { - console.info('ohos_mail-- rename mail success') - } else { - console.info('ohos_mail-- rename mail fail:' + err) - } - }) - - //删除邮箱(文件夹) - store.deleteFolder("TestMail", (success, err) =>{ - if (success) { - console.info('ohos_mail-- delete mail success') - } else { - console.info('ohos_mail-- delete mail fail:' + err) - } - }) - - //获取INBOX邮箱对象(收件箱) - let folder: Folder = store.getFolder("INBOX") - //打开INBOX邮箱 - folder.open(Folder.READ_WRITE, async () => { - //获取邮箱的相关信息 - MailLogger.info('ohos_test-- messageCount--' + folder.getMessageCount()) - MailLogger.info('ohos_test-- unreadMessageCount--' + folder.getUnreadMessageCount()) - MailLogger.info('ohos_test-- newMessageCount--' + folder.getNewMessageCount()) - MailLogger.info('ohos_test-- uidNext--' + folder.getUIDNext()) - MailLogger.info('ohos_test-- UIDValidity--' + folder.getUIDValidity()) - MailLogger.info('ohos_test-- mode--' + folder.getMode()) - MailLogger.info('ohos_test-- name--' + folder.getName()) - MailLogger.info('ohos_test-- fullname--' + folder.getFullName()) - - await new Promise((resolve, reject) => { - //获取已删除邮件个数 - folder.getDeletedMessageCount((success, result) => { - MailLogger.info('ohos_test-- deletedMessageCount--' + result) - resolve(''); }) - }) - .then((result) => { - return new Promise((resolve, reject) => { - //判断当前邮箱是否存在 - folder.exists((success, result) => { - MailLogger.info('ohos_test-- exists--' + result) + + // Obtain an INBOX object. + let folder: Folder = store.getFolder("INBOX") + // Open the inbox. + folder.open(Folder.READ_WRITE, async () => { + // Obtain the mailbox information. + MailLogger.info('ohos_test-- messageCount--' + folder.getMessageCount()) + MailLogger.info('ohos_test-- unreadMessageCount--' + folder.getUnreadMessageCount()) + MailLogger.info('ohos_test-- newMessageCount--' + folder.getNewMessageCount()) + MailLogger.info('ohos_test-- uidNext--' + folder.getUIDNext()) + MailLogger.info('ohos_test-- UIDValidity--' + folder.getUIDValidity()) + MailLogger.info('ohos_test-- mode--' + folder.getMode()) + MailLogger.info('ohos_test-- name--' + folder.getName()) + MailLogger.info('ohos_test-- fullname--' + folder.getFullName()) + + await new Promise((resolve, reject) => { + // Obtain the number of deleted emails. + folder.getDeletedMessageCount((success, result) => { + MailLogger.info('ohos_test-- deletedMessageCount--' + result) resolve(''); }) }) - }) - .then((result) => { - return new Promise((resolve, reject) => { - //获取邮箱列表 - folder.list((success, result) => { - MailLogger.info('ohos_test-- list--' + JSON.stringify(result)) - resolve(''); + .then((result) => { + return new Promise((resolve, reject) => { + // Check whether a mailbox exists. + folder.exists((success, result) => { + MailLogger.info('ohos_test-- exists--' + result) + resolve(''); + }) + }) }) - }) + .then((result) => { + return new Promise((resolve, reject) => { + // Obtain the mailbox list. + folder.list((success, result) => { + MailLogger.info('ohos_test-- list--' + JSON.stringify(result)) + resolve(''); + }) + }) + }) + + // Obtain all emails in the mailbox. + let messages = folder.getMessages() }) - - //获取当前邮箱的所有邮件 - let messages = folder.getMessages() - }) - } - ``` - -14、添加邮件到指定文件夹(只支持QQ、Sina邮箱) - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - try { - let folder: Folder = await store.syncGetFolder("Sent Messages") - folder.open(Folder.READ_WRITE, async (err:Error) => { - if (!err) { - let to: string[] = ["xx@qq.com", "xx@sina.com"]; - let Cc: string[] = ["xx@yeah.net"]; - let Bc: string[] = ["xx@qq.com"]; - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, to) - mimeMessage.setRecipients(RecipientType.CC, Cc) - mimeMessage.setRecipients(RecipientType.BCC, Bc) - mimeMessage.setSubject("主题") - mimeMessage.setMIMEVersion("1.0") - mimeMessage.setHtml("" + "
" + "测试" + "
") - mimeMessage.addAttachmentBody(new AttachmentBody(globalThis.filesPath, "test.jpg")) - - //设置纯文本格式的正文 - mimeMessage.setText("TEST") - await folder.syncAppendMessage(mimeMessage) - await folder.syncExpunge() - MailLogger.info('ohos_mail-- expunge success!') - await store.syncClose() - MailLogger.info('ohos_mail-- close imap success') - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- open folder fail : ' + err) - return - } - }) - } catch (err:Error) { - MailLogger.info('ohos_mail-- imap sync get folder fail:' + err) } - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` + ``` + +15. Add emails to a specified folder (valid only for QQ and Sina mailboxes). + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + try { + let folder: Folder = await store.syncGetFolder("Sent Messages") + folder.open(Folder.READ_WRITE, async (err:Error) => { + if (!err) { + let to: string[] = ["xx@qq.com", "xx@sina.com"]; + let Cc: string[] = ["xx@yeah.net"]; + let Bc: string[] = ["xx@qq.com"]; + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, to) + mimeMessage.setRecipients(RecipientType.CC, Cc) + mimeMessage.setRecipients(RecipientType.BCC, Bc) + mimeMessage.setSubject ("Subject") + mimeMessage.setMIMEVersion("1.0") + mimeMessage.setHtml ("" + "
" + " test "+ "
") + mimeMessage.addAttachmentBody(new AttachmentBody(globalThis.filesPath, "test.jpg")) + + // Set the body in plain text format. + mimeMessage.setText("TEST") + await folder.syncAppendMessage(mimeMessage) + await folder.syncExpunge() + MailLogger.info('ohos_mail-- expunge success!') + await store.syncClose() + MailLogger.info('ohos_mail-- close imap success') + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- open folder fail : ' + err) + return + } + }) + } catch (err:Error) { + MailLogger.info('ohos_mail-- imap sync get folder fail:' + err) + } + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` -## 接口说明 +## Available APIs -### EmlFormat(邮件解析) +### EmlFormat (Parsing an Email) -* 解析邮件类型的文件 +* Parses an email. `parse(path: string, callback)` -* 解析string型的邮件内容 +* Parses the email content of the string type. `parseString(eml: string, parseCallBack)` -* 构建邮件 +* Builds an email. `buildEml(data: Data, callback?)` -### MimeTypeDetector(检测文件Mime类型) +### MimeTypeDetector (Testing MIME Type) -* 检测文件Mime类型 +* Detects the MIME type of a file. `detectMimeType(path: string)` -### Properties(连接邮件服务器的会话信息) +### Properties (Session Information for Connecting to the Email Server) -* 设置发件人(用户名) +* Sets a sender (user name). `setFrom(from: string)` -* 设置服务器地址 +* Sets a server address. `setHost(host: string)` -* 设置端口 +* Sets a port number. `setPort(port: number)` -* 设置邮箱授权码 +* Sets the email authorization code. `setAuthorizationCode(authorizationCode: string)` -* 设置是否使用ssl +* Sets whether to use SSL. `ssl(flag:boolean)` -* 设置ca证书 +* Sets the CA certificate. `ca(ca:string[])` -### TransPort(邮件发送) +### TransPort (Sending an Email) -* 连接接并登录SMTP发件服务器 +* Connects to and logs in to the SMTP sending server. `connect(properties: Properties, loginEvent: (success:boolean, err?:Error) => void)` -* 发送邮件 +* Sends an email. `sendMessage(mimeMessage: MimeMessage, event: (err:Error) => void)` -* 关闭服务器连接 +* Closes server connection. `close(event: (err) => void)` -* 发送空消息 +* Sends an empty message. `noop(event: (err) => void)` -* 设置服务器连接超时时间 +* Sets the server connection timeout interval. `setTimeOut(timeout:number)` -### Store(主要链接服务器,创建、删除、重命名邮箱操作) +### Store (Connecting to a Server, and Creating, Deleting, and Renaming a Mailbox) -* 连接并登录Imap收件服务器 +* Connects to and logs in to the IMAP receiving server. `connect(connectCallback: (success:boolean, err?:Error) => void)` -* 设置连接超时时间 +* Sets the connection timeout interval. `setConnectTimeOut(timeout:number))` -* 关闭链接 +* Closes the connection. `close(callback)` -* 发送空消息 +* Sends an empty message. `noop() ` -* 获取默认Folder +* Obtains the default folder. ` getDefaultFolder(): Folder` -* 更具邮箱名称获取邮箱对象(Promise) +* Obtains a mailbox object based on the mailbox name (in promise mode). `syncGetFolder(name: string): Promise` -* 更具邮箱名称获取邮箱对象(callback形式) +* Obtains a mailbox object based on the mailbox name (in callback mode). `getFolder(name: string,callback)` -* 创建邮箱(文件夹) +* Creates a mailbox (folder). `createFolder(name: string, callBack)` -* 删除邮箱(文件夹) +* Deletes a mailbox (folder). `deleteFolder(name: string, callBack)` -* 重命名邮箱(文件夹) +* Renames a mailbox (folder). `renameFolder(oldName: string, newName: string, callBack)` -* 结束邮件接收过程,pop3接收到此命令后删除所有设置删除标记的邮件,并关闭与pop3客户端程序的网络链接。 +* Ends the mail receiving process. After receiving this command, POP3 deletes all emails with the DELE flag and closes the network connection with the POP3 client. `quit()` -### MimeMessage(构建邮件结构体) +### MimeMessage (Building Email Structure) -* 设置发件人 +* Sets a sender. `setFrom(from: string)` -* 设置收件人 +* Sets a recipient. `setRecipients(addressType: RecipientType, addresses: string[])` -* 通过收件人类型追加收件人 +* Adds recipients by recipient type. `addRecipients(addressType: RecipientType, addresses: string[])` -* 设置html +* Sets an HTML file. `setHtml(html: string)` -* 添加html内嵌图片 +* Adds an HTML embedded image. `addImgInside(imgInside: MimeBodyPart)` -* 设置日期 +* Sets a date. `setSentDate(date: Date)` -* 添加附件 +* Adds an attachment. `addAttachmentBody(attachmentBody: AttachmentBody)` -* 设置主题 +* Sets the subject. - `setSubject("测试邮件发送")` + `setSubject ("Email sending test")` -* 设置邮件正文 +* Sets the email body. - `setText("这是一个邮件测试邮件")` + `setText("This is a test email.")` -* 设置MIMEVersion +* Sets the MIME version. `setMIMEVersion("1.0")` -* 获取构建的邮件内容 +* Obtains the email content. `getMimeMessage()` -### Message(读取邮件后解析的结果集) +### Message (Result Set Parsed After the Email Is Read) -* 获取Folder +* Obtains a folder. `getFolder(): Folder` -* 设置邮件Flag +* Sets an email flag. `setFlags(flags: Flag[], isAdd: boolean, callback)` -* 获取邮件Flag +* Obtains an email flag. `getFlags(callback)` -* 同步获取邮件Flag +* Synchronously obtains an email flag. `syncGetFlags(): Promise` -* 获取发送日期 +* Obtains the date when the email was sent. `getSentDate(): string` -* 获取邮件行数 +* Obtains the number of lines in the email body. `getLineCount():number` -* 获取邮件大小 +* Obtains the email size. `getSize(callback)` -* 获取邮件完整内容(callback形式) +* Obtains the complete email content (in callback mode). `getContent(callback)` -* 获取邮件完整内容(promise形式) +* Obtains the complete email content (in promise mode). - `syncGetContent():Promise` + `syncGetContent(): Promise` -* POP3同步获取邮件Header以及正文的前几行(promise形式) +* Synchronously obtains the email header and the first several lines of the email body (in promise mode). `syncGetLineContent(lineCount): Promise` -* POP3获取邮件Header以及正文的前几行(promise形式) +* Obtains the email header and the first several lines of the email body (in promise mode). `getLineContent(lineCount, callback)` -* 获取邮件标号 +* Obtains the email number. `getMessageNumber(): number` -* 获取邮件主题 +* Obtains the email subject. `getSubject(): string` -* 获取发件人 +* Obtains the sender. `getFrom(): string[]` -* 获取ReplyTo +* Obtains ReplyTo. `getReplyTo(): string[]` -* 获取收件人 +* Obtains the recipients. `getRecipients(addressType: RecipientType): string[]` -* 获取所有收件人 +* Obtains all recipients. `getAllRecipients(): string[]` -* 获取邮件文本内容 +* Obtains the email content. `getText()` -* 获取附件列表 +* Obtains the attachments. `getFiles()` -* 获取内联附件列表 +* Obtains the inline attachments. `getInlineFiles()` -* 获取html +* Obtains the HTML content. `getHtml()` -* 获取MIMEVersion +* Obtains the MIME version. `getMIMEVersion(callback)` -* 获取Header +* Obtains the header. `getHeader(headerName: string, callback)` -* 获取所有Header +* Obtains all headers. `getAllHeaders(callback)` -* 获取所是否含有附件(包括内联图片) +* Checks whether attachments (including inline images) are contained. `isIncludeAttachment(): boolean` -### Folder(邮箱工具类) +### Folder (Mailbox Utility Class) -* 获取Store +* Obtains the store. `getStore(): Store` -* 获取邮箱列表 +* Obtains the folder list. `list(callback)` -* 打开Folder +* Opens a folder `open(mode: number, callback)` -* 关闭连接 +* Closes the connection. `close()` -* 获取当前Folder是否打开 +* Checks whether the folder is opened. `isOpen(): boolean` -* 通过编号获取邮件对象 +* Obtains an email object based on the number. `getMessage(msgNums: number)` -* 移动邮件 +* Moves an email. `moveMessages(srcMsg: Message[], folder: Folder, callback)` -* 复制邮件到指定文件夹 +* Copies an email to the specified folder. `copyMessages(srcMsg: Message[], folder: Folder, callback)` -* 判断folder是否存在 +* Checks whether a folder exists. `exists(callback)` -* 删除被标记为delete的邮件(callback形式) +* Deletes emails marked as delete (in callback mode). `expunge(callback)` -* 删除被标记为delete的邮件(promise形式) +* Deletes emails marked as delete (in promise mode). `syncExpunge(): Promise ` -* 获取所有邮件个数 +* Obtains the number of all emails. `getMessageCount(): number` -* 获取未读邮件个数 +* Obtains the number of unread emails. `getUnreadMessageCount(): number` -* 获取最新邮件个数 +* Obtains the number of latest emails. `getNewMessageCount(): number` -* 获取删除邮件个数 +* Obtains the number of deleted emails. `getDeletedMessageCount(callback)` -* 获取打开模式 +* Obtains the open mode. `getMode(): number` -* 获取folder名称 +* Obtains the folder name. `getName(): string` -* 获取下一封新邮件的UID +* Obtains the UID of the next new email. `getUIDNext(): number` -* 获取UIDValidity +* Checks the validity of a UID. `getUIDValidity(): number` -* 获取获取所有邮件 +* Obtains all emails. `getMessages(): Message[]` -* 获取邮件UID +* Obtains the UID of an email. `getUID(message: Message, callback)` -* 同步获取邮件UID +* Synchronously obtains the UID of an email. `syncGetUID(message: Message): Promise` -* 通过UID获取邮件 +* Obtains an email by UID. `getMessageByUID(uid: string,callback)` -* 通过UID同步获取邮件 +* Synchronously obtains an email by UID. `syncGetMessageByUID(uid: string):Promise` -* 添加邮件到指定文件夹(callback形式) +* Adds an email to the specified folder (in callback mode). `appendMessage(message: MimeMessage, callback:(err) => void)` -* 添加邮件到指定文件夹(promise形式) +* Adds an email to the specified folder (in promise mode). `syncAppendMessage(message: MimeMessage): Promise` -### MimeMultipart(imap 邮件实体类) +### MimeMultipart (IMAP Mail Entity Class) -* 获取TextSize +* Obtains the text size. `getTextSize():number` -* 获取Store +* Obtains the store. `getCount():number` -* 获取所有附件 +* Obtains all attachments. `getAttachmentFilesDigest(): Array` -* 获取所有内联附件 +* Obtains all inline attachments. `getInlineAttachmentFilesDigest(): Array` -* 获取附件个数 +* Obtains the number of attachments. `getAttachmentSize(): number` -* 获取内联附件个数 +* Obtains the number of inline attachments. `getInlineAttachmentSize(): number` -* 是否包含附件 +* Checks whether attachments are included. `isIncludeAttachment(): boolean` -* 是否包含内联附件 +* Checks whether inline attachments are included. `isIncludeInlineAttachment(): boolean` -* 获取正文(Promise形式) +* Obtains the email body (in promise mode). `syncGetText(): Promise` -* IMAP获取正文前几行(Promise形式) +* Obtains the first several lines of the email body (in promise mode). `syncGetPartText(size: number): Promise` -* 获取正文(callback形式) +* Obtains the email body (in callback mode). `getText(callback)` -* IMAP获取正文前几行(callback形式) +* Obtains the first several lines of the email body (in callback mode). `getPartText(size: number, callback)` -* 获取Html(Promise形式) +* Obtains the HTML content (in promise mode). `syncGetHtml(): Promise` -* IMAP获取Html前几行(Promise形式) +* Obtains the first several lines of the HTML content (in promise mode). `syncGetPartHtml(size: number): Promise` -* 获取Html(callback形式) +* Obtains the HTML content (in callback mode). `getHtml(callback)` -* IMAP获取Html前几行(callback形式) +* Obtains the first several lines of the HTML content (in callback mode). `getPartHtml(size: number, callback)` -* 获取calendar(Promise形式) +* Obtains the calendar (in promise mode). `syncGetCalendar(): Promise` -* 获取calendar(callback形式) +* Obtains the calendar (in callback mode). `getCalendar(callback)` -* 获取calendar长度 +* Obtains the calendar length. `getCalendarSize()` -* 获取第index个附件,不包括附件内容数据,附件内容数据通过getAttachmentContent获取 +* Obtains the attachment with the given index, excluding the attachment content, which can be obtained through `getAttachmentContent`. `getAttachment(index)` -* 获取第index个内联附件,不包括附件内容数据,附件内容数据通过getInlineAttachmentContent获取 +* Obtains the inline attachment with the given index, excluding the attachment content, which can be obtained through `getInlineAttachmentContent`. `getInlineAttachment(index)` -* 获取指定附件内容(callback形式) +* Obtains the content of the specified attachment (in callback mode). `getAttachmentContent(index, callback)` -* 获取指定内联附件内容(callback形式) +* Obtains the content of the specified inline attachment (in callback mode). `getInlineAttachmentContent(index, callback)` -## 约束与限制 +## Constraints -在下述版本验证通过: +This project has been verified in the following versions: -- DevEco Studio: 4.1 Canary2(4.1.3.325), SDK: API11 Release(4.1.0.36) -- DevEco Studio: 4.0 Release(4.0.3.415), SDK: API10 Release(4.0.10.6) +- DevEco Studio: 4.1 Canary2 (4.1.3.325), SDK: API 11 Release (4.1.0.36) +- DevEco Studio: 4.0 Release (4.0.3.415), SDK: API 10 Release (4.0.10.6) -## 目录结构 +## Directory Structure ```` |---- mail -| |---- entry # 示例代码文件夹 -| |---- library # mail库文件夹 +| |---- entry # Sample code +| |---- library # mail library | |---- src | |---- main | |---- ets | |---- mime_types -| |---- JList.ts # 数据集合 -| |---- MimeTypeDetector.ts # MIME文件探测器 -| |---- WeightedMimeType.ts # MIME文件属性 +| |---- JList.ts # Data set +| |---- MimeTypeDetector.ts # MIME file detector +| |---- WeightedMimeType.ts # MIME file attributes | |---- emlformat -| |---- Attachment.ts # 附件实体 -| |---- Boundary.ts # 邮件解析辅助 -| |---- Data.ts # 构造邮件数据实体 -| |---- EmlFormat.ts # 邮件解析 -| |---- Result.ts # 邮件解析结果 +| |---- Attachment.ts # Attachment entity +| |---- Boundary.ts # Email parsing assistance +| |---- Data.ts # Used to construct email data +| |---- EmlFormat.ts # Used to parse emails +| |---- Result.ts # Email parsing result | |---- mail -| |---- AttachmentBody.ts # 附件实体 -| |---- Flag.ts # 连接邮件服务器的会话信息 -| |---- Folder.ts # 邮箱管理 -| |---- Message.ts # 邮件实体类 -| |---- MimeBodyPart.ts # HTML内嵌图片实体 -| |---- MimeMessage.ts # 邮件实体 -| |---- MimeMultipart.ts # imap邮件实体 -| |---- Properties.ts # 连接邮件服务器的会话信息 -| |---- RecipientType.ts # 收件人类型 -| |---- ResponseCode.ts # smtp服务器响应码 -| |---- SocketUtil.ts # socket工具 -| |---- Store.ts # 邮件接收、管理 -| |---- TransPort.ts # 邮件发送 - |---- GlobalContext.ts # GlobalContext替代globalThis -| |---- Constant.ts 常量 -| |---- MailLogger.ts 日志工具 -| |---- Uft7Base64.ts utf7转base64工具 -| |---- Utf7Util.ts utf7编解码工具 -| |---- Util.ts 工具 -| |---- index.ets # 对外接口 -| |---- README.md # 安装使用方法 +| |---- AttachmentBody.ts # Attachment entity +| |---- Flag.ts # Session information for connection to the email server +| |---- Folder.ts # Email management +| |---- Message.ts # Email entity class +| |---- MimeBodyPart.ts # HTML embedded image entity +| |---- MimeMessage.ts # Email entity +| |---- MimeMultipart.ts # IMAP email entity +| |---- Properties.ts # Session information for connection to the email server +| |---- RecipientType.ts # Recipient type +| |---- ResponseCode.ts # SMTP server response code +| |---- SocketUtil.ts # Socket utility +| |---- Store.ts # Email receiving and management +| |---- TransPort.ts # Email sending + |---- GlobalContext.ts # GlobalContext replaces globalThis. +| |---- Constant.ts # Constants +| |---- MailLogger.ts # Logger +| |---- Uft7Base64.ts # Utility for converting UTF-7 to Base64 +| |---- Utf7Util.ts # Utility for encoding and decoding UTF-7 +| |---- Util.ts # Utilities +| |---- index.ets # External APIs +| |---- README.md # Readme ```` -## 贡献代码 +## How to Contribute -使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc/ohos_mail/issues)给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-tpc/ohos_mail/pulls) -。 +If you find any problem during the use, submit an [issue](https://gitee.com/openharmony-tpc/ohos_mail/issues) or a [PR](https://gitee.com/openharmony-tpc/ohos_mail/pulls). -## 开源协议 +## License -本项目基于 [Eclipse Public License version 2.0](https://gitee.com/openharmony-tpc/ohos_mail/blob/master/LICENSE-EPL-2.0-GPL-2.0-with-classpath-exception) ,请自由地享受和参与开源。 +This project is licensed under [Eclipse Public License version 2.0](https://gitee.com/openharmony-tpc/ohos_mail/blob/master/LICENSE-EPL-2.0-GPL-2.0-with-classpath-exception). -## 相关项目 +## Related Projects -- [emlformat](https://github.com/papnkukn/eml-format) —— 用于解析和构建EML文件的纯Node.js库,即RFC 822中描述的电子邮件格式。 -- [emailjs-utf7](https://github.com/emailjs/emailjs-utf7) —— 将JavaScript(Unicode/UCS-2)字符串编码和解码为UTF-7 ASCII字符串。 -- [emailjs-base64](https://github.com/emailjs/emailjs-base64) —— Base64对字符串和类型化数组进行编码。 \ No newline at end of file +- [emlformat](https://github.com/papnkukn/eml-format): A pure Node.js library for parsing and building EML files, that is, email format described in RFC 822. +- [emailjs-utf7](https://github.com/emailjs/emailjs-utf7): A library for encoding and decoding JavaScript (Unicode/UCS-2) strings into UTF-7 ASCII strings. +- [emailjs-base64](https://github.com/emailjs/emailjs-base64): A library for encoding strings and typed arrays using Base64. diff --git a/README_EN.md b/README_EN.md deleted file mode 100644 index 9126f915b9b6e953d2a7418a37f3f6d12573c623..0000000000000000000000000000000000000000 --- a/README_EN.md +++ /dev/null @@ -1,1281 +0,0 @@ -# mail - - -## Introduction - -> ohos_mail provides features such as sending, receiving, moving, and deleting emails in accordance with the SMTP, POP3, and IMAP protocols. It can parse and construct emails in EML format and identify MIME message headers and bodies of emails. -> The code in the `/mail/src/main/ets/mail/` directory is the implementation of the open source software [mail](https://github.com/eclipse-ee4j/mail) using TypeScript. -> The code in the `/mail/src/main/ets/mime_types/` directory is the implementation of the open source software [mime-types](https://github.com/overview/mime-types) using TypeScript. - -![log.gif](image/sample_EN.gif) - -## How to Install - -```shell -ohpm install @ohos/mail -``` - -For details about the OpenHarmony ohpm environment configuration, see [OpenHarmony HAR](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.en.md). - -## Precautions for Using Test Resources - -The test resource files are uploaded to the `./testFile` directory in git lfs mode. If you directly download the .zip package of the project, only the shortcuts of the resource files are obtained. You need to manually download the files from the resource file directory. Alternatively, download the code in git clone mode. In this way, the obtained resource files are complete. - -## How to Use - -#### Before using the demo, change *xx* in the demo or XTS to the correct email account and authorization code. - -1. Import the dependency. - - ``` - import { MimeTypeDetector,EmlFormat,Store,Attachment } from '@ohos/mail'; - ``` - -2. Add permissions in the `module.json5` file. - - ``` - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - }, - { - "name": "ohos.permission.GET_NETWORK_INFO" - }, - { - "name": "ohos.permission.GET_WIFI_INFO" - } - ] - ``` - -3. Initialize `MimeTypeDetector` in the EntryAbility. - - ``` - onWindowStageCreate(windowStage) { - MimeTypeDetector.init((data)=>{ - GlobalContext.getContext().setValue("cacheContent", data); - }) - } - ``` - -4. Parse the MIME type of a file. - - ``` - // Parse the MIME type of a file. - let mimetype =MimeTypeDetector.detectMimeType(path + "/logdemo.bat") - console.log('sample mimetype detectMimeType bat:' + mimetype); - ``` - -5. Parse an email. - - ``` - // Parse an email. - let filePath = path + '/sample.eml' - new EmlFormat().parse(filePath, function (error, result) { - console.info('result-------' + JSON.stringify(result)) - }); - - // Parse the email content of the string type. - let content="' - EmlFormat.parseString(content, (error, msg: Message) => { - // Obtain the detailed information about the email. - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getFrom()[0])) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getSubject())) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getRecipients(RecipientType.TO))) - MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getText())) - MailLogger.info('ohos_test-- html--' + JSON.stringify(result.getHtml())) - MailLogger.info('ohos_test-- file--' + JSON.stringify(result.getFiles())) - ... - }); - ``` - -6. Construct an email. - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject("") - mimeMessage.setMIMEVersion("1.0") - - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - // Set the body in plain text format. - mimeMessage.setText("test") - // Set an HTML file. - // mimeMessage.setHtml("" + "
" + text + "
") - // Set an HTML file with an image. - let contentId = "imag01" - mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId)) - let contentId1 = "imag02" - mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId1)) - mimeMessage.setHtml("" - + "
" + this.text - + "" - + "" - + "

") - - // Set an attachment. - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) - let buildResult:string = mimeMessage.getMimeMessage() - ``` - -7. Set the protocol for reading the email. (IMAP and POP3 are supported.) - - ``` - // Set the IMAP protocol. - let properties = new Properties("imap") - // Set the address of the IMAP server. - properties.setHost("imap.qq.com") - // Set the port number of the IMAP server. - properties.setPort(143) - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - // Set the POP3 protocol. - let properties = new Properties("pop3") - // Set the address of the POP3 server. - properties.setHost("pop.qq.com") - // Set the port number of the POP3 server. - properties.setPort(110) - ``` - -8. Send an email. - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let properties = new Properties() - properties.setFrom(this.from) - properties.setHost(this.host) - properties.setPort(this.port) - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - properties.setAuthorizationCode(this.authorizationCode) - this.transport = new TransPort() - // Connect to the service. - this.transport.connect(properties, (success:boolean, err:Error) =>{ - if (success) { - MailLogger.info('ohos_mail-- login smtp success:') - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject("") - mimeMessage.setMIMEVersion("1.0") - - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - // Set the body in plain text format. - mimeMessage.setText("") - // Set an HTML file. - // mimeMessage.setHtml("" + "
" + text + "
") - // Set an HTML file with an image. - let contentId = "imag01" - mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId)) - let contentId1 = "imag02" - mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId1)) - mimeMessage.setHtml("" - + "
" + this.text - + "" - + "" - + "

") - - // Set an attachment. - let attachment1=new AttachmentBody(path, "test.txt") - // Call the following method to pass in GlobalContext.getContext().getValue('cacheContent') only if the function is used in the TaskPool. - //attachment1.setCacheContent(GlobalContext.getContext().getValue('cacheContent')) - mimeMessage.addAttachmentBody(attachment1) - mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.docx")) - // Send the email. - this.transport.sendMessage(mimeMessage, (success: boolean, err:Error) =>{ - if (success) { - MailLogger.info('ohos_mail-- send mail success!'); - prompt.showToast({message:"Sent successfully.", duration:4000}) - } else { - prompt.showToast({message:"Sending failed: "+ JSON.stringify(err), duration:4000}) - } - // Close the connection. - this.transport.close((err:Error) => { - if (!err) { - MailLogger.info('ohos_mail-- socket close success!'); - } else { - MailLogger.info('ohos_mail-- socket close fail:' + err); - } - }) - }) - - } else { - prompt.showToast({message:JSON.stringify(err), duration:4000}) - MailLogger.error('ohos_mail-- login smtp fail:' + err); - } - }); - ``` - -9. Receive an email (IMAP). - - ``` - let properties = new Properties("imap") - properties.setHost(this.hostReceive) - properties.setPort(this.portReceive) - properties.setFrom(this.from) - properties.setAuthorizationCode(this.authorizationCode) - properties.ssl(this.isSSL) - if (this.isSSL) { - properties.ca(this.ca) - } - let map::Map = new Map() - map.set("name", "myname"); - map.set("version", "1.0.0"); - map.set("vendor", "myclient"); - map.set("support-email", "xx@test.com"); - - let store = new Store(properties) - if (this.hostReceive.includes("126") || this.hostReceive.includes("163") - || this.hostReceive.includes("yeah")) { - store.id(map) - } - store.connect(async (success: boolean, err:Error) => { - if (success) { - // Obtain the folder list. - store.getDefaultFolder().list((success:boolean, folders:Folder) => { - if (success) { - for (let i = 0; i < folders.length; i++) { - MailLogger.info("ohos_mail folder list----"+folders[i].getName()) - } - } - }) - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async (err:Error) => { - if (!err) { - let messages = folder.getMessages() - if (messages.length > 0 && messages.length >= this.readMsgIndex) { - let msg = messages[this.readMsgIndex-1] - msg.getAllHeaders(async (success:boolean, msg: Message) => { - if (success) { - this.parseResult += 'Headers ' + '\r\n' - + 'From:' + msg.getFrom()[0] + "\r\n" - + 'To:' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" - + 'Subject:' + msg.getSubject() + "\r\n" - + 'Date: ' + msg.getSentDate () - + "\r\n------------------------------------\r\n\r\n" - } - - try { - let result = await msg.syncGetContent() - let mime = result as MimeMultipart - - try { - let textBody = await mime.syncGetText() - this.parseResult += 'Body' + '\r\n' - + 'Data: ' + textBody.getContent() + "\r\n" - + 'CharSet: ' + textBody.getCharSet() + "\r\n" - + 'MimeType: ' + textBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + textBody.getTransferEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getText fail:' + err) - } - - try { - let htmlBody = await mime.syncGetHtml() - this.parseResult += 'Html ' + '\r\n' - + 'Data: ' + htmlBody.getContent() + "\r\n" - + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" - + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + htmlBody.getTransferEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getHtml fail:' + err) - } - - let attachCount = mime.getAttachmentSize() - for (let i = 0; i < attachCount; i++) { - try { - let attachBody = await mime.syncGetAttachment(i) - this.parseResult += 'Attachment' + i + '\r\n' - + 'FileName: ' + attachBody.getFileName() + "\r\n" - + 'Data: ' + attachBody.getContent() + "\r\n" - + 'CharSet: ' + attachBody.getCharSet() + "\r\n" - + 'MimeType: ' + attachBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + attachBody.getEncoding() - + "\r\n------------------------------------\r\n\r\n" - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getAttachment fail:' + err) - } - } - - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- close imap success') - } else { - MailLogger.info('ohos_mail-- close imap fail') - } - }) - } catch (err:Error) { - MailLogger.info('ohos_mail-- sync getContent fail:' + err) - } - }) - } - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- open folder fail : ' + err) - return - } - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` - -10. Receive an email (POP3). - - ``` - let properties = new Properties("pop3") - properties.setHost(this.hostReceive) - properties.setPort(this.portReceive) - properties.setFrom(this.from) - properties.setAuthorizationCode(this.authorizationCode) - properties.ssl(this.isSSL) - if (this.isSSL) { - properties.ca(this.ca) - } - - let store = new Store(properties) - store.connect((success:boolean, err:Error) => { - if (success) { - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async (err:Error) => { - let messages = folder.getMessages() - if (messages.length > 0 && messages.length >= this.readMsgIndex) { - let msg = messages[this.readMsgIndex-1] - // Obtain the parsed email content. - try { - let message = await msg.syncGetContent() - let result = message as Message - this.parseResult = 'From:' + result.getFrom()[0] + "\r\n\r\n" - + 'Subject:' + result.getSubject() + "\r\n\r\n" - + 'To:' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" - + 'Body:' + result.getText() + "\r\n\r\n" - + 'HTML: ' + result.getHtml() + "\r\n\r\n" - - let files = result.getFiles() - if (!!files) { - let length = files.length - for (let i = 0; i < length; i++) { - this.parseResult += "Attachment" + (i + 1) +": " + files[i].getFileName() + "\r\n" - + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n" - + " Content-Type:" + files[i].getMimeType() + "\r\n" - + " Attachment content: " + files[i].getData() + "\r\n" - } - } - - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- close imap success') - } else { - MailLogger.info('ohos_mail-- close imap fail') - } - }) - } catch (e) { - MailLogger.info('ohos_mail-- sync getContent fail:' + err) - } - } - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 2500 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` - -11. Delete an email. - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom("xxx@qq.com") - properties.setAuthorizationCode("xx") - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success: boolean, err:Error) => { - if (success) { - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, () => { - let msgs = folder.getMessages() - msgs[this.deleteMsgIndex-1].setFlag(Flag.DELETED, (success, result) => { - if (success) { - folder.expunge() - } - }) - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` - -12. Move an email. - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - // Obtain an INBOX object. - let folder: Folder = store.getFolder("INBOX") - // Open the inbox. - folder.open(Folder.READ_WRITE, async () => { - // Obtain all emails in the mailbox. - let messages = folder.getMessages() - folder.moveMessages([messages[0]], new Folder('Sent Messages'),(success,err)=>{ - if(success){ - MailLogger.info('ohos_mail-- moveMessages success') - }else{ - MailLogger.info('ohos_mail-- moveMessages fail : ' + err) - } - }) - - // Some mailboxes do not support the move function. You can use the following method to implement move: - folder.copyMessages([messages[0]], new Folder('Drafts'), (success, err) => { - if (success) { - MailLogger.info('ohos_mail-- copyMessages success') - } else { - MailLogger.info('ohos_mail-- copyMessages fail : ' + err) - } - messages[0].setFlag(Flag.DELETED, (err:Error) => { - if (!err) { - MailLogger.info('ohos_mail-- set flag success') - } else { - MailLogger.info('ohos_mail-- set flag fail') - } - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- set flag close success') - } else { - MailLogger.info('ohos_mail-- set flag close fail') - } - }) - }) - }) - }) - ``` - -13. Forward or reply to an email. - - ``` - private from: string = "xx@qq.com"; - private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; - private Cc: string[] = ["xx@qq.com"]; - private Bc: string[] = ["xx@qq.com"]; - - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort("143") - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - let store = new Store(properties) - store.connect((success:boolean, err:Error) => { - if (success) { - let folder: Folder = store.getFolder("INBOX") - folder.open(Folder.READ_WRITE, async () => { - let messages = folder.getMessages() - messages[0].getContent((success, message: Message) => { - let properties = new Properties() - properties.setFrom(this.from) - properties.setHost("smtp.qq.com") - properties.setPort(25) - properties.setAuthorizationCode("xx") - this.transport = new TransPort() - // Connect to the service. - this.transport.connect(properties, (success:boolean, err:Error) => { - if (success) { - MailLogger.info('ohos_mail-- login smtp success:'); - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, this.to) - mimeMessage.setRecipients(RecipientType.CC, this.Cc) - mimeMessage.setRecipients(RecipientType.BCC, this.Bc) - mimeMessage.setSubject ("Forward:"+ message.getSubject ()) - - let text = "Forward Test\r\n\r\n\r\n" - + "------------------ Original email ------------------\r\n" - + "From: " + message.getFrom()[0] + "\r\n" - + "Sent at: " + message.getSentDate() + "\r\n" - let to = message.getRecipients(RecipientType.TO) - if (!!to) { - text += "To:" - for (let i = 0; i < to.length; i++) { - if (i != to.length - 1) { - text += to[i] + " , " - } else { - text += to[i] + "\r\n" - } - } - } - - text += "Subject: " + message.getSubject() + "\r\n" - let cc = message.getRecipients(RecipientType.CC) - if (!!cc) { - text += "Cc:" - for (let i = 0; i < cc.length; i++) { - if (i != cc.length - 1) { - text += cc[i] + " , " - } else { - text += cc[i] + "\r\n" - } - } - } - +"\r\n\r\n" - + message.getText() - // Set the body in plain text format. - mimeMessage.setText(text) - // Set an HTML file. - mimeMessage.setHtml(message.getHtml()) - let files = message.getFiles() - let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" - if (!!files) { - for (let i = 0;i < files.length; i++) { - let file = files[i] - if (!!file.getContentID()) { - var mimeBody = new MimeBodyPart(path, file.getFileName(), file.getContentID()) - mimeBody.setDta(file.getUint8ArrayData()) - mimeBody.setMimeType(file.getMimeType()) - mimeMessage.addImgInside(mimeBody) - } else { - mimeMessage.addAttachmentBody(file) - } - } - } - // Forward the email. - this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) => { - if (success) { - MailLogger.info('ohos_mail-- send message success'); - prompt.showToast({ message: "Forwarded successfully.", duration: 4000 }) - } else { - prompt.showToast({ message:"Forwarding failed: "+ JSON.stringify(err), duration: 4000 }) - } - - store.close((success:boolean) => { - if (success) { - MailLogger.info('ohos_mail-- close imap success') - } else { - MailLogger.info('ohos_mail-- close imap fail') - } - }) - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login smtp fail:' + err); - } - }); - }) - }) - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err); - } - }) - ``` - -14. Manage the mailbox. - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(25) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - // Set whether to use SSL. - properties.ssl(true) - // Set the CA certificate. - properties.ca(this.ca) - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - // Create a mailbox (folder). - store.createFolder("Test", (success, err) =>{ - if (success) { - console.info('ohos_mail-- create mail success') - } else { - console.info('ohos_mail-- create mail fail:' + err) - } - }) - - // Rename a mailbox (folder). - store.renameFolder("Test", "TestMail", (success, err) =>{ - if (success) { - console.info('ohos_mail-- rename mail success') - } else { - console.info('ohos_mail-- rename mail fail:' + err) - } - }) - - // Delete a mailbox (folder). - store.deleteFolder("TestMail", (success, err) =>{ - if (success) { - console.info('ohos_mail-- delete mail success') - } else { - console.info('ohos_mail-- delete mail fail:' + err) - } - }) - - // Obtain an INBOX object. - let folder: Folder = store.getFolder("INBOX") - // Open the inbox. - folder.open(Folder.READ_WRITE, async () => { - // Obtain the mailbox information. - MailLogger.info('ohos_test-- messageCount--' + folder.getMessageCount()) - MailLogger.info('ohos_test-- unreadMessageCount--' + folder.getUnreadMessageCount()) - MailLogger.info('ohos_test-- newMessageCount--' + folder.getNewMessageCount()) - MailLogger.info('ohos_test-- uidNext--' + folder.getUIDNext()) - MailLogger.info('ohos_test-- UIDValidity--' + folder.getUIDValidity()) - MailLogger.info('ohos_test-- mode--' + folder.getMode()) - MailLogger.info('ohos_test-- name--' + folder.getName()) - MailLogger.info('ohos_test-- fullname--' + folder.getFullName()) - - await new Promise((resolve, reject) => { - // Obtain the number of deleted emails. - folder.getDeletedMessageCount((success, result) => { - MailLogger.info('ohos_test-- deletedMessageCount--' + result) - resolve(''); - }) - }) - .then((result) => { - return new Promise((resolve, reject) => { - // Check whether a mailbox exists. - folder.exists((success, result) => { - MailLogger.info('ohos_test-- exists--' + result) - resolve(''); - }) - }) - }) - .then((result) => { - return new Promise((resolve, reject) => { - // Obtain the mailbox list. - folder.list((success, result) => { - MailLogger.info('ohos_test-- list--' + JSON.stringify(result)) - resolve(''); - }) - }) - }) - - // Obtain all emails in the mailbox. - let messages = folder.getMessages() - }) - } - ``` - -15. Add emails to a specified folder (valid only for QQ and Sina mailboxes). - - ``` - let properties = new Properties("imap") - properties.setHost("imap.qq.com") - properties.setPort(143) - properties.setFrom(this.from) - properties.setAuthorizationCode("xx") - let store = new Store(properties) - store.connect(async (success:boolean, err:Error) => { - if (success) { - try { - let folder: Folder = await store.syncGetFolder("Sent Messages") - folder.open(Folder.READ_WRITE, async (err:Error) => { - if (!err) { - let to: string[] = ["xx@qq.com", "xx@sina.com"]; - let Cc: string[] = ["xx@yeah.net"]; - let Bc: string[] = ["xx@qq.com"]; - let mimeMessage = new MimeMessage() - mimeMessage.setFrom(this.from) - mimeMessage.setRecipients(RecipientType.TO, to) - mimeMessage.setRecipients(RecipientType.CC, Cc) - mimeMessage.setRecipients(RecipientType.BCC, Bc) - mimeMessage.setSubject ("Subject") - mimeMessage.setMIMEVersion("1.0") - mimeMessage.setHtml ("" + "
" + " test "+ "
") - mimeMessage.addAttachmentBody(new AttachmentBody(globalThis.filesPath, "test.jpg")) - - // Set the body in plain text format. - mimeMessage.setText("TEST") - await folder.syncAppendMessage(mimeMessage) - await folder.syncExpunge() - MailLogger.info('ohos_mail-- expunge success!') - await store.syncClose() - MailLogger.info('ohos_mail-- close imap success') - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- open folder fail : ' + err) - return - } - }) - } catch (err:Error) { - MailLogger.info('ohos_mail-- imap sync get folder fail:' + err) - } - } else { - prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) - MailLogger.info('ohos_mail-- login IMAP fail : ' + err) - } - }) - ``` - -## Available APIs - -### EmlFormat (Parsing an Email) - -* Parses an email. - - `parse(path: string, callback)` - -* Parses the email content of the string type. - - `parseString(eml: string, parseCallBack)` - -* Builds an email. - - `buildEml(data: Data, callback?)` - -### MimeTypeDetector (Testing MIME Type) - -* Detects the MIME type of a file. - - `detectMimeType(path: string)` - -### Properties (Session Information for Connecting to the Email Server) - -* Sets a sender (user name). - - `setFrom(from: string)` - -* Sets a server address. - - `setHost(host: string)` - -* Sets a port number. - - `setPort(port: number)` - -* Sets the email authorization code. - - `setAuthorizationCode(authorizationCode: string)` - -* Sets whether to use SSL. - - `ssl(flag:boolean)` - -* Sets the CA certificate. - - `ca(ca:string[])` - -### TransPort (Sending an Email) - -* Connects to and logs in to the SMTP sending server. - - `connect(properties: Properties, loginEvent: (success:boolean, err?:Error) => void)` - -* Sends an email. - - `sendMessage(mimeMessage: MimeMessage, event: (err:Error) => void)` - -* Closes server connection. - - `close(event: (err) => void)` - -* Sends an empty message. - - `noop(event: (err) => void)` - -* Sets the server connection timeout interval. - - `setTimeOut(timeout:number)` - -### Store (Connecting to a Server, and Creating, Deleting, and Renaming a Mailbox) - -* Connects to and logs in to the IMAP receiving server. - - `connect(connectCallback: (success:boolean, err?:Error) => void)` - -* Sets the connection timeout interval. - - `setConnectTimeOut(timeout:number))` - -* Closes the connection. - - `close(callback)` - -* Sends an empty message. - - `noop() ` - -* Obtains the default folder. - - ` getDefaultFolder(): Folder` - -* Obtains a mailbox object based on the mailbox name (in promise mode). - - `syncGetFolder(name: string): Promise` - -* Obtains a mailbox object based on the mailbox name (in callback mode). - - `getFolder(name: string,callback)` - -* Creates a mailbox (folder). - - `createFolder(name: string, callBack)` - -* Deletes a mailbox (folder). - - `deleteFolder(name: string, callBack)` - -* Renames a mailbox (folder). - - `renameFolder(oldName: string, newName: string, callBack)` - -* Ends the mail receiving process. After receiving this command, POP3 deletes all emails with the DELE flag and closes the network connection with the POP3 client. - - `quit()` - -### MimeMessage (Building Email Structure) - -* Sets a sender. - - `setFrom(from: string)` - -* Sets a recipient. - - `setRecipients(addressType: RecipientType, addresses: string[])` - -* Adds recipients by recipient type. - - `addRecipients(addressType: RecipientType, addresses: string[])` - -* Sets an HTML file. - - `setHtml(html: string)` - -* Adds an HTML embedded image. - - `addImgInside(imgInside: MimeBodyPart)` - -* Sets a date. - - `setSentDate(date: Date)` - -* Adds an attachment. - - `addAttachmentBody(attachmentBody: AttachmentBody)` - -* Sets the subject. - - `setSubject ("Email sending test")` - -* Sets the email body. - - `setText("This is a test email.")` - -* Sets the MIME version. - - `setMIMEVersion("1.0")` - -* Obtains the email content. - - `getMimeMessage()` - -### Message (Result Set Parsed After the Email Is Read) - -* Obtains a folder. - - `getFolder(): Folder` - -* Sets an email flag. - - `setFlags(flags: Flag[], isAdd: boolean, callback)` - -* Obtains an email flag. - - `getFlags(callback)` - -* Synchronously obtains an email flag. - - `syncGetFlags(): Promise` - -* Obtains the date when the email was sent. - - `getSentDate(): string` - -* Obtains the number of lines in the email body. - - `getLineCount():number` - -* Obtains the email size. - - `getSize(callback)` - -* Obtains the complete email content (in callback mode). - - `getContent(callback)` - -* Obtains the complete email content (in promise mode). - - `syncGetContent(): Promise` - -* Synchronously obtains the email header and the first several lines of the email body (in promise mode). - - `syncGetLineContent(lineCount): Promise` - -* Obtains the email header and the first several lines of the email body (in promise mode). - - `getLineContent(lineCount, callback)` - -* Obtains the email number. - - `getMessageNumber(): number` - -* Obtains the email subject. - - `getSubject(): string` - -* Obtains the sender. - - `getFrom(): string[]` - -* Obtains ReplyTo. - - `getReplyTo(): string[]` - -* Obtains the recipients. - - `getRecipients(addressType: RecipientType): string[]` - -* Obtains all recipients. - - `getAllRecipients(): string[]` - -* Obtains the email content. - - `getText()` - -* Obtains the attachments. - - `getFiles()` - -* Obtains the inline attachments. - - `getInlineFiles()` - -* Obtains the HTML content. - - `getHtml()` - -* Obtains the MIME version. - - `getMIMEVersion(callback)` - -* Obtains the header. - - `getHeader(headerName: string, callback)` - -* Obtains all headers. - - `getAllHeaders(callback)` - -* Checks whether attachments (including inline images) are contained. - - `isIncludeAttachment(): boolean` - -### Folder (Mailbox Utility Class) - -* Obtains the store. - - `getStore(): Store` - -* Obtains the folder list. - - `list(callback)` - -* Opens a folder - - `open(mode: number, callback)` - -* Closes the connection. - - `close()` - -* Checks whether the folder is opened. - - `isOpen(): boolean` - -* Obtains an email object based on the number. - - `getMessage(msgNums: number)` - -* Moves an email. - - `moveMessages(srcMsg: Message[], folder: Folder, callback)` - -* Copies an email to the specified folder. - - `copyMessages(srcMsg: Message[], folder: Folder, callback)` - -* Checks whether a folder exists. - - `exists(callback)` - -* Deletes emails marked as delete (in callback mode). - - `expunge(callback)` - -* Deletes emails marked as delete (in promise mode). - - `syncExpunge(): Promise ` - -* Obtains the number of all emails. - - `getMessageCount(): number` - -* Obtains the number of unread emails. - - `getUnreadMessageCount(): number` - -* Obtains the number of latest emails. - - `getNewMessageCount(): number` - -* Obtains the number of deleted emails. - - `getDeletedMessageCount(callback)` - -* Obtains the open mode. - - `getMode(): number` - -* Obtains the folder name. - - `getName(): string` - -* Obtains the UID of the next new email. - - `getUIDNext(): number` - -* Checks the validity of a UID. - - `getUIDValidity(): number` - -* Obtains all emails. - - `getMessages(): Message[]` - -* Obtains the UID of an email. - - `getUID(message: Message, callback)` - -* Synchronously obtains the UID of an email. - - `syncGetUID(message: Message): Promise` - -* Obtains an email by UID. - - `getMessageByUID(uid: string,callback)` - -* Synchronously obtains an email by UID. - - `syncGetMessageByUID(uid: string):Promise` - -* Adds an email to the specified folder (in callback mode). - - `appendMessage(message: MimeMessage, callback:(err) => void)` - -* Adds an email to the specified folder (in promise mode). - - `syncAppendMessage(message: MimeMessage): Promise` - - -### MimeMultipart (IMAP Mail Entity Class) - -* Obtains the text size. - - `getTextSize():number` - - -* Obtains the store. - - `getCount():number` - -* Obtains all attachments. - - `getAttachmentFilesDigest(): Array` - -* Obtains all inline attachments. - - `getInlineAttachmentFilesDigest(): Array` - -* Obtains the number of attachments. - - `getAttachmentSize(): number` - -* Obtains the number of inline attachments. - - `getInlineAttachmentSize(): number` - -* Checks whether attachments are included. - - `isIncludeAttachment(): boolean` - -* Checks whether inline attachments are included. - - `isIncludeInlineAttachment(): boolean` - -* Obtains the email body (in promise mode). - - `syncGetText(): Promise` - -* Obtains the first several lines of the email body (in promise mode). - - `syncGetPartText(size: number): Promise` - -* Obtains the email body (in callback mode). - - `getText(callback)` - -* Obtains the first several lines of the email body (in callback mode). - - `getPartText(size: number, callback)` - -* Obtains the HTML content (in promise mode). - - `syncGetHtml(): Promise` - -* Obtains the first several lines of the HTML content (in promise mode). - - `syncGetPartHtml(size: number): Promise` - -* Obtains the HTML content (in callback mode). - - `getHtml(callback)` - -* Obtains the first several lines of the HTML content (in callback mode). - - `getPartHtml(size: number, callback)` - -* Obtains the calendar (in promise mode). - - `syncGetCalendar(): Promise` - -* Obtains the calendar (in callback mode). - - `getCalendar(callback)` - -* Obtains the calendar length. - - `getCalendarSize()` - -* Obtains the attachment with the given index, excluding the attachment content, which can be obtained through `getAttachmentContent`. - `getAttachment(index)` - -* Obtains the inline attachment with the given index, excluding the attachment content, which can be obtained through `getInlineAttachmentContent`. - `getInlineAttachment(index)` - -* Obtains the content of the specified attachment (in callback mode). - - `getAttachmentContent(index, callback)` - -* Obtains the content of the specified inline attachment (in callback mode). - - `getInlineAttachmentContent(index, callback)` - -## Constraints - -This project has been verified in the following versions: - -- DevEco Studio: 4.1 Canary2 (4.1.3.325), SDK: API 11 Release (4.1.0.36) -- DevEco Studio: 4.0 Release (4.0.3.415), SDK: API 10 Release (4.0.10.6) - -## Directory Structure - -```` -|---- mail -| |---- entry # Sample code -| |---- library # mail library -| |---- src -| |---- main -| |---- ets -| |---- mime_types -| |---- JList.ts # Data set -| |---- MimeTypeDetector.ts # MIME file detector -| |---- WeightedMimeType.ts # MIME file attributes -| |---- emlformat -| |---- Attachment.ts # Attachment entity -| |---- Boundary.ts # Email parsing assistance -| |---- Data.ts # Used to construct email data -| |---- EmlFormat.ts # Used to parse emails -| |---- Result.ts # Email parsing result -| |---- mail -| |---- AttachmentBody.ts # Attachment entity -| |---- Flag.ts # Session information for connection to the email server -| |---- Folder.ts # Email management -| |---- Message.ts # Email entity class -| |---- MimeBodyPart.ts # HTML embedded image entity -| |---- MimeMessage.ts # Email entity -| |---- MimeMultipart.ts # IMAP email entity -| |---- Properties.ts # Session information for connection to the email server -| |---- RecipientType.ts # Recipient type -| |---- ResponseCode.ts # SMTP server response code -| |---- SocketUtil.ts # Socket utility -| |---- Store.ts # Email receiving and management -| |---- TransPort.ts # Email sending - |---- GlobalContext.ts # GlobalContext replaces globalThis. -| |---- Constant.ts # Constants -| |---- MailLogger.ts # Logger -| |---- Uft7Base64.ts # Utility for converting UTF-7 to Base64 -| |---- Utf7Util.ts # Utility for encoding and decoding UTF-7 -| |---- Util.ts # Utilities -| |---- index.ets # External APIs -| |---- README_EN.md # Readme -```` - -## How to Contribute - -If you find any problem during the use, submit an [issue](https://gitee.com/openharmony-tpc/ohos_mail/issues) or a [PR](https://gitee.com/openharmony-tpc/ohos_mail/pulls). - -## License - -This project is licensed under [Eclipse Public License version 2.0](https://gitee.com/openharmony-tpc/ohos_mail/blob/master/LICENSE-EPL-2.0-GPL-2.0-with-classpath-exception). - -## Related Projects - -- [emlformat](https://github.com/papnkukn/eml-format): A pure Node.js library for parsing and building EML files, that is, email format described in RFC 822. -- [emailjs-utf7](https://github.com/emailjs/emailjs-utf7): A library for encoding and decoding JavaScript (Unicode/UCS-2) strings into UTF-7 ASCII strings. -- [emailjs-base64](https://github.com/emailjs/emailjs-base64): A library for encoding strings and typed arrays using Base64. diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..dabe7d0412a31bba9b35d748ad69eb53e2bf7790 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,1280 @@ +# mail + + +## 简介 + +> ohos_mail主要提供电子邮件SMTP、POP3、IMAP协议的发送、接收、移动、删除等功能,能够解析和构建eml格式的电子邮件,识别电子邮件的MIME类型消息头和消息体,方便开发者执行一些常用的邮件传输。 +> 其中本软件/mail/src/main/ets/mail/目录下的代码是开源软件 [mail](https://github.com/eclipse-ee4j/mail) 的TypeScript语言实现; +> 以及本软件/mail/src/main/ets/mime_types/目录下的代码是开源软件 [mime-types](https://github.com/overview/mime-types) 的TypeScript语言实现。 + +## 下载安装 + +```shell +ohpm install @ohos/mail +``` + +OpenHarmony ohpm环境配置等更多内容,请参考 [如何安装OpenHarmony ohpm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) 。 + +## 测试资源使用注意事项 + +内置的测试资源文件放在./testFile目录下,通过git lfs的方式上传的,如果直接下载项目的zip包,得到的资源文件只是一个快捷方式,需要进资源文件目录手动下载。或者通过git clone的方式下载代码,这样得到的资源文件是完整的。 + +## 使用说明 + +#### 使用前在demo或者XTS中的xx改为正确的邮箱账号和授权码,才可正常的使用demo。 + +1、引入依赖 + + ``` + import { MimeTypeDetector,EmlFormat,Store,Attachment } from '@ohos/mail'; + ``` + +2、在module.json5中添加权限 + + ``` + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name": "ohos.permission.GET_NETWORK_INFO" + }, + { + "name": "ohos.permission.GET_WIFI_INFO" + } + ] + ``` + +3、在EntryAbility初始化MimeTypeDetector + + ``` + onWindowStageCreate(windowStage) { + MimeTypeDetector.init((data)=>{ + GlobalContext.getContext().setValue("cacheContent", data); + }) + } + ``` + +4、文件Mime类型解析 + + ``` + //解析文件的MimeType + let mimetype =MimeTypeDetector.detectMimeType(path + "/logdemo.bat") + console.log('sample mimetype detectMimeType bat:' + mimetype); + ``` + +5、邮件解析 + + ``` + //解析邮件文件 + let filePath = path + '/sample.eml' + new EmlFormat().parse(filePath, function (error, result) { + console.info('result-------' + JSON.stringify(result)) + }); + + //解析string类型的邮件内容 + let content="' + EmlFormat.parseString(content, (error, msg: Message) => { + //获取邮件各种详细信息 + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getFrom()[0])) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getSubject())) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getRecipients(RecipientType.TO))) + MailLogger.info('ohos_test-- text--' + JSON.stringify(result.getText())) + MailLogger.info('ohos_test-- html--' + JSON.stringify(result.getHtml())) + MailLogger.info('ohos_test-- file--' + JSON.stringify(result.getFiles())) + ... + }); + ``` + +6、构建邮件 + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject("") + mimeMessage.setMIMEVersion("1.0") + + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + //设置纯文本格式的正文 + mimeMessage.setText("test") + //设置html格式文件 + // mimeMessage.setHtml("" + "
" + text + "
") + //设置html格式文件带图片 + let contentId = "imag01" + mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId)) + let contentId1 = "imag02" + mimeMessage.addImgInside(new MimeBodyPart(path, "test.png", contentId1)) + mimeMessage.setHtml("" + + "
" + this.text + + "" + + "" + + "

") + + //设置附件 + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.png")) + let buildResult:string = mimeMessage.getMimeMessage() + ``` + +7、设置读取邮箱的协议(支持IMAP和POP3协议) + + ``` + //设置imap协议 + let properties = new Properties("imap") + //设置imap服务器地址 + properties.setHost("imap.qq.com") + //设置imap服务器端口 + properties.setPort(143) + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + //设置pop3协议 + let properties = new Properties("pop3") + //设置pop3服务器地址 + properties.setHost("pop.qq.com") + //设置pop3服务器端口 + properties.setPort(110) + ``` + +8、发送邮件 + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let properties = new Properties() + properties.setFrom(this.from) + properties.setHost(this.host) + properties.setPort(this.port) + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + properties.setAuthorizationCode(this.authorizationCode) + this.transport = new TransPort() + //连接服务 + this.transport.connect(properties, (success:boolean, err:Error) =>{ + if (success) { + MailLogger.info('ohos_mail-- login smtp success:') + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject("") + mimeMessage.setMIMEVersion("1.0") + + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + //设置纯文本格式的正文 + mimeMessage.setText("") + //设置html格式文件 + // mimeMessage.setHtml("" + "
" + text + "
") + //设置html格式文件带图片 + let contentId = "imag01" + mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId)) + let contentId1 = "imag02" + mimeMessage.addImgInside(new MimeBodyPart(GlobalContext.getContext().getValue('filesPath') as string, "test.png", contentId1)) + mimeMessage.setHtml("" + + "
" + this.text + + "" + + "" + + "

") + + //设置附件 + let attachment1=new AttachmentBody(path, "test.txt") + //如果是在taskpool中使用需要调用下面方法将GlobalContext.getContext().getValue('cacheContent')传递进去,反之可以不用调 + //attachment1.setCacheContent(GlobalContext.getContext().getValue('cacheContent')) + mimeMessage.addAttachmentBody(attachment1) + mimeMessage.addAttachmentBody(new AttachmentBody(path, "test.docx")) + //发送邮件 + this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) =>{ + if (success) { + MailLogger.info('ohos_mail-- send mail success!'); + prompt.showToast({message:"发送成功!", duration:4000}) + } else { + prompt.showToast({message:"发送失败:" + JSON.stringify(err), duration:4000}) + } + //关闭连接 + this.transport.close((err:Error) => { + if (!err) { + MailLogger.info('ohos_mail-- socket close success!'); + } else { + MailLogger.info('ohos_mail-- socket close fail:' + err); + } + }) + }) + + } else { + prompt.showToast({message:JSON.stringify(err), duration:4000}) + MailLogger.error('ohos_mail-- login smtp fail:' + err); + } + }); + ``` + +9、接收邮件(imap) + + ``` + let properties = new Properties("imap") + properties.setHost(this.hostReceive) + properties.setPort(this.portReceive) + properties.setFrom(this.from) + properties.setAuthorizationCode(this.authorizationCode) + properties.ssl(this.isSSL) + if (this.isSSL) { + properties.ca(this.ca) + } + let map::Map = new Map() + map.set("name", "myname"); + map.set("version", "1.0.0"); + map.set("vendor", "myclient"); + map.set("support-email", "xx@test.com"); + + let store = new Store(properties) + if (this.hostReceive.includes("126") || this.hostReceive.includes("163") + || this.hostReceive.includes("yeah")) { + store.id(map) + } + store.connect(async (success: boolean, err:Error) => { + if (success) { + //获取文件夹列表 + store.getDefaultFolder().list((success:boolean, folders:Folder) => { + if (success) { + for (let i = 0; i < folders.length; i++) { + MailLogger.info("ohos_mail folder list----"+folders[i].getName()) + } + } + }) + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async (err:Error) => { + if (!err) { + let messages = folder.getMessages() + if (messages.length > 0 && messages.length >= this.readMsgIndex) { + let msg = messages[this.readMsgIndex-1] + msg.getAllHeaders(async (success:boolean, msg: Message) => { + if (success) { + this.parseResult += 'Headers ' + '\r\n' + + '发件人: ' + msg.getFrom()[0] + "\r\n" + + '收件人: ' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" + + '主题: ' + msg.getSubject() + "\r\n" + + '日期: ' + msg.getSentDate() + + "\r\n------------------------------------\r\n\r\n" + } + + try { + let result = await msg.syncGetContent() + let mime = result as MimeMultipart + + try { + let textBody = await mime.syncGetText() + this.parseResult += '正文 ' + '\r\n' + + 'Data: ' + textBody.getContent() + "\r\n" + + 'CharSet: ' + textBody.getCharSet() + "\r\n" + + 'MimeType: ' + textBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + textBody.getTransferEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getText fail:' + err) + } + + try { + let htmlBody = await mime.syncGetHtml() + this.parseResult += 'Html ' + '\r\n' + + 'Data: ' + htmlBody.getContent() + "\r\n" + + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" + + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + htmlBody.getTransferEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getHtml fail:' + err) + } + + let attachCount = mime.getAttachmentSize() + for (let i = 0; i < attachCount; i++) { + try { + let attachBody = await mime.syncGetAttachment(i) + this.parseResult += '附件 ' + i + '\r\n' + + 'FileName: ' + attachBody.getFileName() + "\r\n" + + 'Data: ' + attachBody.getContent() + "\r\n" + + 'CharSet: ' + attachBody.getCharSet() + "\r\n" + + 'MimeType: ' + attachBody.getMimeType() + "\r\n" + + 'TransferEncoding: ' + attachBody.getEncoding() + + "\r\n------------------------------------\r\n\r\n" + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getAttachment fail:' + err) + } + } + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + } catch (err:Error) { + MailLogger.info('ohos_mail-- sync getContent fail:' + err) + } + }) + } + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- open folder fail : ' + err) + return + } + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` + +10、接收邮件(pop3) + + ``` + let properties = new Properties("pop3") + properties.setHost(this.hostReceive) + properties.setPort(this.portReceive) + properties.setFrom(this.from) + properties.setAuthorizationCode(this.authorizationCode) + properties.ssl(this.isSSL) + if (this.isSSL) { + properties.ca(this.ca) + } + + let store = new Store(properties) + store.connect((success:boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async (err:Error) => { + let messages = folder.getMessages() + if (messages.length > 0 && messages.length >= this.readMsgIndex) { + let msg = messages[this.readMsgIndex-1] + //获取解析后的邮件内容 + try { + let message = await msg.syncGetContent() + let result = message as Message + this.parseResult = '发件人: ' + result.getFrom()[0] + "\r\n\r\n" + + '主题: ' + result.getSubject() + "\r\n\r\n" + + '收件人: ' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" + + '正文: ' + result.getText() + "\r\n\r\n" + + 'HTML: ' + result.getHtml() + "\r\n\r\n" + + let files = result.getFiles() + if (!!files) { + let length = files.length + for (let i = 0; i < length; i++) { + this.parseResult += "附件 " + (i + 1) + ": " + files[i].getFileName() + "\r\n" + + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n" + + " Content-Type:" + files[i].getMimeType() + "\r\n" + + " 附件内容:" + files[i].getData() + "\r\n" + } + } + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + } catch (e) { + MailLogger.info('ohos_mail-- sync getContent fail:' + err) + } + } + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 2500 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` + +11、删除邮件 + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom("xxx@qq.com") + properties.setAuthorizationCode("xx") + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + let store = new Store(properties) + store.connect(async (success: boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, () => { + let msgs = folder.getMessages() + msgs[this.deleteMsgIndex-1].setFlag(Flag.DELETED, (success, result) => { + if (success) { + folder.expunge() + } + }) + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` + +12、移动邮件 + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + //获取INBOX邮箱对象(收件箱) + let folder: Folder = store.getFolder("INBOX") + //打开INBOX邮箱 + folder.open(Folder.READ_WRITE, async () => { + //获取当前邮箱的所有邮件 + let messages = folder.getMessages() + folder.moveMessages([messages[0]], new Folder('Sent Messages'),(success,err)=>{ + if(success){ + MailLogger.info('ohos_mail-- moveMessages success') + }else{ + MailLogger.info('ohos_mail-- moveMessages fail : ' + err) + } + }) + + //部分邮箱不支持MOVE 可以使用以下方式实现MOVE功能 + folder.copyMessages([messages[0]], new Folder('草稿箱'), (success, err) => { + if (success) { + MailLogger.info('ohos_mail-- copyMessages success') + } else { + MailLogger.info('ohos_mail-- copyMessages fail : ' + err) + } + messages[0].setFlag(Flag.DELETED, (err:Error) => { + if (!err) { + MailLogger.info('ohos_mail-- set flag success') + } else { + MailLogger.info('ohos_mail-- set flag fail') + } + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- set flag close success') + } else { + MailLogger.info('ohos_mail-- set flag close fail') + } + }) + }) + }) + }) + ``` + +13、转发/回复 邮件 + + ``` + private from: string = "xx@qq.com"; + private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; + private Cc: string[] = ["xx@qq.com"]; + private Bc: string[] = ["xx@qq.com"]; + + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort("143") + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + let store = new Store(properties) + store.connect((success:boolean, err:Error) => { + if (success) { + let folder: Folder = store.getFolder("INBOX") + folder.open(Folder.READ_WRITE, async () => { + let messages = folder.getMessages() + messages[0].getContent((success, message: Message) => { + let properties = new Properties() + properties.setFrom(this.from) + properties.setHost("smtp.qq.com") + properties.setPort(25) + properties.setAuthorizationCode("xx") + this.transport = new TransPort() + //连接服务 + this.transport.connect(properties, (success:boolean, err:Error) => { + if (success) { + MailLogger.info('ohos_mail-- login smtp success:'); + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, this.to) + mimeMessage.setRecipients(RecipientType.CC, this.Cc) + mimeMessage.setRecipients(RecipientType.BCC, this.Bc) + mimeMessage.setSubject("转发:" + message.getSubject()) + + let text = "转发测试\r\n\r\n\r\n" + + "------------------ 原始邮件 ------------------\r\n" + + "发件人: " + message.getFrom()[0] + "\r\n" + + "发送时间: " + message.getSentDate() + "\r\n" + let to = message.getRecipients(RecipientType.TO) + if (!!to) { + text += "收件人: " + for (let i = 0; i < to.length; i++) { + if (i != to.length - 1) { + text += to[i] + " , " + } else { + text += to[i] + "\r\n" + } + } + } + + text += "主题: " + message.getSubject() + "\r\n" + let cc = message.getRecipients(RecipientType.CC) + if (!!cc) { + text += "抄送: " + for (let i = 0; i < cc.length; i++) { + if (i != cc.length - 1) { + text += cc[i] + " , " + } else { + text += cc[i] + "\r\n" + } + } + } + +"\r\n\r\n" + + message.getText() + //设置纯文本格式的正文 + mimeMessage.setText(text) + //设置html + mimeMessage.setHtml(message.getHtml()) + let files = message.getFiles() + let path:string="/data/app/el2/100/base/cn.openharmony.mail/haps/entry/files" + if (!!files) { + for (let i = 0;i < files.length; i++) { + let file = files[i] + if (!!file.getContentID()) { + var mimeBody = new MimeBodyPart(path, file.getFileName(), file.getContentID()) + mimeBody.setDta(file.getUint8ArrayData()) + mimeBody.setMimeType(file.getMimeType()) + mimeMessage.addImgInside(mimeBody) + } else { + mimeMessage.addAttachmentBody(file) + } + } + } + //转发邮件 + this.transport.sendMessage(mimeMessage, (success:boolean, err:Error) => { + if (success) { + MailLogger.info('ohos_mail-- send message success'); + prompt.showToast({ message: "转发成功!", duration: 4000 }) + } else { + prompt.showToast({ message: "转发失败:" + JSON.stringify(err), duration: 4000 }) + } + + store.close((success:boolean) => { + if (success) { + MailLogger.info('ohos_mail-- close imap success') + } else { + MailLogger.info('ohos_mail-- close imap fail') + } + }) + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login smtp fail:' + err); + } + }); + }) + }) + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err); + } + }) + ``` + +14、邮箱管理 + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(25) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + //设置是否使用ssl + properties.ssl(true) + //设置ca证书 + properties.ca(this.ca) + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + //创建邮箱(文件夹) + store.createFolder("Test", (success, err) =>{ + if (success) { + console.info('ohos_mail-- create mail success') + } else { + console.info('ohos_mail-- create mail fail:' + err) + } + }) + + //重命名邮箱(文件夹) + store.renameFolder("Test", "TestMail", (success, err) =>{ + if (success) { + console.info('ohos_mail-- rename mail success') + } else { + console.info('ohos_mail-- rename mail fail:' + err) + } + }) + + //删除邮箱(文件夹) + store.deleteFolder("TestMail", (success, err) =>{ + if (success) { + console.info('ohos_mail-- delete mail success') + } else { + console.info('ohos_mail-- delete mail fail:' + err) + } + }) + + //获取INBOX邮箱对象(收件箱) + let folder: Folder = store.getFolder("INBOX") + //打开INBOX邮箱 + folder.open(Folder.READ_WRITE, async () => { + //获取邮箱的相关信息 + MailLogger.info('ohos_test-- messageCount--' + folder.getMessageCount()) + MailLogger.info('ohos_test-- unreadMessageCount--' + folder.getUnreadMessageCount()) + MailLogger.info('ohos_test-- newMessageCount--' + folder.getNewMessageCount()) + MailLogger.info('ohos_test-- uidNext--' + folder.getUIDNext()) + MailLogger.info('ohos_test-- UIDValidity--' + folder.getUIDValidity()) + MailLogger.info('ohos_test-- mode--' + folder.getMode()) + MailLogger.info('ohos_test-- name--' + folder.getName()) + MailLogger.info('ohos_test-- fullname--' + folder.getFullName()) + + await new Promise((resolve, reject) => { + //获取已删除邮件个数 + folder.getDeletedMessageCount((success, result) => { + MailLogger.info('ohos_test-- deletedMessageCount--' + result) + resolve(''); + }) + }) + .then((result) => { + return new Promise((resolve, reject) => { + //判断当前邮箱是否存在 + folder.exists((success, result) => { + MailLogger.info('ohos_test-- exists--' + result) + resolve(''); + }) + }) + }) + .then((result) => { + return new Promise((resolve, reject) => { + //获取邮箱列表 + folder.list((success, result) => { + MailLogger.info('ohos_test-- list--' + JSON.stringify(result)) + resolve(''); + }) + }) + }) + + //获取当前邮箱的所有邮件 + let messages = folder.getMessages() + }) + } + ``` + +14、添加邮件到指定文件夹(只支持QQ、Sina邮箱) + + ``` + let properties = new Properties("imap") + properties.setHost("imap.qq.com") + properties.setPort(143) + properties.setFrom(this.from) + properties.setAuthorizationCode("xx") + let store = new Store(properties) + store.connect(async (success:boolean, err:Error) => { + if (success) { + try { + let folder: Folder = await store.syncGetFolder("Sent Messages") + folder.open(Folder.READ_WRITE, async (err:Error) => { + if (!err) { + let to: string[] = ["xx@qq.com", "xx@sina.com"]; + let Cc: string[] = ["xx@yeah.net"]; + let Bc: string[] = ["xx@qq.com"]; + let mimeMessage = new MimeMessage() + mimeMessage.setFrom(this.from) + mimeMessage.setRecipients(RecipientType.TO, to) + mimeMessage.setRecipients(RecipientType.CC, Cc) + mimeMessage.setRecipients(RecipientType.BCC, Bc) + mimeMessage.setSubject("主题") + mimeMessage.setMIMEVersion("1.0") + mimeMessage.setHtml("" + "
" + "测试" + "
") + mimeMessage.addAttachmentBody(new AttachmentBody(globalThis.filesPath, "test.jpg")) + + //设置纯文本格式的正文 + mimeMessage.setText("TEST") + await folder.syncAppendMessage(mimeMessage) + await folder.syncExpunge() + MailLogger.info('ohos_mail-- expunge success!') + await store.syncClose() + MailLogger.info('ohos_mail-- close imap success') + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- open folder fail : ' + err) + return + } + }) + } catch (err:Error) { + MailLogger.info('ohos_mail-- imap sync get folder fail:' + err) + } + } else { + prompt.showToast({ message: JSON.stringify(err), duration: 4000 }) + MailLogger.info('ohos_mail-- login IMAP fail : ' + err) + } + }) + ``` + +## 接口说明 + +### EmlFormat(邮件解析) + +* 解析邮件类型的文件 + + `parse(path: string, callback)` + +* 解析string型的邮件内容 + + `parseString(eml: string, parseCallBack)` + +* 构建邮件 + + `buildEml(data: Data, callback?)` + +### MimeTypeDetector(检测文件Mime类型) + +* 检测文件Mime类型 + + `detectMimeType(path: string)` + +### Properties(连接邮件服务器的会话信息) + +* 设置发件人(用户名) + + `setFrom(from: string)` + +* 设置服务器地址 + + `setHost(host: string)` + +* 设置端口 + + `setPort(port: number)` + +* 设置邮箱授权码 + + `setAuthorizationCode(authorizationCode: string)` + +* 设置是否使用ssl + + `ssl(flag:boolean)` + +* 设置ca证书 + + `ca(ca:string[])` + +### TransPort(邮件发送) + +* 连接接并登录SMTP发件服务器 + + `connect(properties: Properties, loginEvent: (success:boolean, err?:Error) => void)` + +* 发送邮件 + + `sendMessage(mimeMessage: MimeMessage, event: (err:Error) => void)` + +* 关闭服务器连接 + + `close(event: (err) => void)` + +* 发送空消息 + + `noop(event: (err) => void)` + +* 设置服务器连接超时时间 + + `setTimeOut(timeout:number)` + +### Store(主要链接服务器,创建、删除、重命名邮箱操作) + +* 连接并登录Imap收件服务器 + + `connect(connectCallback: (success:boolean, err?:Error) => void)` + +* 设置连接超时时间 + + `setConnectTimeOut(timeout:number))` + +* 关闭链接 + + `close(callback)` + +* 发送空消息 + + `noop() ` + +* 获取默认Folder + + ` getDefaultFolder(): Folder` + +* 更具邮箱名称获取邮箱对象(Promise) + + `syncGetFolder(name: string): Promise` + +* 更具邮箱名称获取邮箱对象(callback形式) + + `getFolder(name: string,callback)` + +* 创建邮箱(文件夹) + + `createFolder(name: string, callBack)` + +* 删除邮箱(文件夹) + + `deleteFolder(name: string, callBack)` + +* 重命名邮箱(文件夹) + + `renameFolder(oldName: string, newName: string, callBack)` + +* 结束邮件接收过程,pop3接收到此命令后删除所有设置删除标记的邮件,并关闭与pop3客户端程序的网络链接。 + + `quit()` + +### MimeMessage(构建邮件结构体) + +* 设置发件人 + + `setFrom(from: string)` + +* 设置收件人 + + `setRecipients(addressType: RecipientType, addresses: string[])` + +* 通过收件人类型追加收件人 + + `addRecipients(addressType: RecipientType, addresses: string[])` + +* 设置html + + `setHtml(html: string)` + +* 添加html内嵌图片 + + `addImgInside(imgInside: MimeBodyPart)` + +* 设置日期 + + `setSentDate(date: Date)` + +* 添加附件 + + `addAttachmentBody(attachmentBody: AttachmentBody)` + +* 设置主题 + + `setSubject("测试邮件发送")` + +* 设置邮件正文 + + `setText("这是一个邮件测试邮件")` + +* 设置MIMEVersion + + `setMIMEVersion("1.0")` + +* 获取构建的邮件内容 + + `getMimeMessage()` + +### Message(读取邮件后解析的结果集) + +* 获取Folder + + `getFolder(): Folder` + +* 设置邮件Flag + + `setFlags(flags: Flag[], isAdd: boolean, callback)` + +* 获取邮件Flag + + `getFlags(callback)` + +* 同步获取邮件Flag + + `syncGetFlags(): Promise` + +* 获取发送日期 + + `getSentDate(): string` + +* 获取邮件行数 + + `getLineCount():number` + +* 获取邮件大小 + + `getSize(callback)` + +* 获取邮件完整内容(callback形式) + + `getContent(callback)` + +* 获取邮件完整内容(promise形式) + + `syncGetContent():Promise` + +* POP3同步获取邮件Header以及正文的前几行(promise形式) + + `syncGetLineContent(lineCount): Promise` + +* POP3获取邮件Header以及正文的前几行(promise形式) + + `getLineContent(lineCount, callback)` + +* 获取邮件标号 + + `getMessageNumber(): number` + +* 获取邮件主题 + + `getSubject(): string` + +* 获取发件人 + + `getFrom(): string[]` + +* 获取ReplyTo + + `getReplyTo(): string[]` + +* 获取收件人 + + `getRecipients(addressType: RecipientType): string[]` + +* 获取所有收件人 + + `getAllRecipients(): string[]` + +* 获取邮件文本内容 + + `getText()` + +* 获取附件列表 + + `getFiles()` + +* 获取内联附件列表 + + `getInlineFiles()` + +* 获取html + + `getHtml()` + +* 获取MIMEVersion + + `getMIMEVersion(callback)` + +* 获取Header + + `getHeader(headerName: string, callback)` + +* 获取所有Header + + `getAllHeaders(callback)` + +* 获取所是否含有附件(包括内联图片) + + `isIncludeAttachment(): boolean` + +### Folder(邮箱工具类) + +* 获取Store + + `getStore(): Store` + +* 获取邮箱列表 + + `list(callback)` + +* 打开Folder + + `open(mode: number, callback)` + +* 关闭连接 + + `close()` + +* 获取当前Folder是否打开 + + `isOpen(): boolean` + +* 通过编号获取邮件对象 + + `getMessage(msgNums: number)` + +* 移动邮件 + + `moveMessages(srcMsg: Message[], folder: Folder, callback)` + +* 复制邮件到指定文件夹 + + `copyMessages(srcMsg: Message[], folder: Folder, callback)` + +* 判断folder是否存在 + + `exists(callback)` + +* 删除被标记为delete的邮件(callback形式) + + `expunge(callback)` + +* 删除被标记为delete的邮件(promise形式) + + `syncExpunge(): Promise ` + +* 获取所有邮件个数 + + `getMessageCount(): number` + +* 获取未读邮件个数 + + `getUnreadMessageCount(): number` + +* 获取最新邮件个数 + + `getNewMessageCount(): number` + +* 获取删除邮件个数 + + `getDeletedMessageCount(callback)` + +* 获取打开模式 + + `getMode(): number` + +* 获取folder名称 + + `getName(): string` + +* 获取下一封新邮件的UID + + `getUIDNext(): number` + +* 获取UIDValidity + + `getUIDValidity(): number` + +* 获取获取所有邮件 + + `getMessages(): Message[]` + +* 获取邮件UID + + `getUID(message: Message, callback)` + +* 同步获取邮件UID + + `syncGetUID(message: Message): Promise` + +* 通过UID获取邮件 + + `getMessageByUID(uid: string,callback)` + +* 通过UID同步获取邮件 + + `syncGetMessageByUID(uid: string):Promise` + +* 添加邮件到指定文件夹(callback形式) + + `appendMessage(message: MimeMessage, callback:(err) => void)` + +* 添加邮件到指定文件夹(promise形式) + + `syncAppendMessage(message: MimeMessage): Promise` + + +### MimeMultipart(imap 邮件实体类) + +* 获取TextSize + + `getTextSize():number` + + +* 获取Store + + `getCount():number` + +* 获取所有附件 + + `getAttachmentFilesDigest(): Array` + +* 获取所有内联附件 + + `getInlineAttachmentFilesDigest(): Array` + +* 获取附件个数 + + `getAttachmentSize(): number` + +* 获取内联附件个数 + + `getInlineAttachmentSize(): number` + +* 是否包含附件 + + `isIncludeAttachment(): boolean` + +* 是否包含内联附件 + + `isIncludeInlineAttachment(): boolean` + +* 获取正文(Promise形式) + + `syncGetText(): Promise` + +* IMAP获取正文前几行(Promise形式) + + `syncGetPartText(size: number): Promise` + +* 获取正文(callback形式) + + `getText(callback)` + +* IMAP获取正文前几行(callback形式) + + `getPartText(size: number, callback)` + +* 获取Html(Promise形式) + + `syncGetHtml(): Promise` + +* IMAP获取Html前几行(Promise形式) + + `syncGetPartHtml(size: number): Promise` + +* 获取Html(callback形式) + + `getHtml(callback)` + +* IMAP获取Html前几行(callback形式) + + `getPartHtml(size: number, callback)` + +* 获取calendar(Promise形式) + + `syncGetCalendar(): Promise` + +* 获取calendar(callback形式) + + `getCalendar(callback)` + +* 获取calendar长度 + + `getCalendarSize()` + +* 获取第index个附件,不包括附件内容数据,附件内容数据通过getAttachmentContent获取 + `getAttachment(index)` + +* 获取第index个内联附件,不包括附件内容数据,附件内容数据通过getInlineAttachmentContent获取 + `getInlineAttachment(index)` + +* 获取指定附件内容(callback形式) + + `getAttachmentContent(index, callback)` + +* 获取指定内联附件内容(callback形式) + + `getInlineAttachmentContent(index, callback)` + +## 约束与限制 + +在下述版本验证通过: + +- DevEco Studio: 4.1 Canary2(4.1.3.325), SDK: API11 Release(4.1.0.36) +- DevEco Studio: 4.0 Release(4.0.3.415), SDK: API10 Release(4.0.10.6) + +## 目录结构 + +```` +|---- mail +| |---- entry # 示例代码文件夹 +| |---- library # mail库文件夹 +| |---- src +| |---- main +| |---- ets +| |---- mime_types +| |---- JList.ts # 数据集合 +| |---- MimeTypeDetector.ts # MIME文件探测器 +| |---- WeightedMimeType.ts # MIME文件属性 +| |---- emlformat +| |---- Attachment.ts # 附件实体 +| |---- Boundary.ts # 邮件解析辅助 +| |---- Data.ts # 构造邮件数据实体 +| |---- EmlFormat.ts # 邮件解析 +| |---- Result.ts # 邮件解析结果 +| |---- mail +| |---- AttachmentBody.ts # 附件实体 +| |---- Flag.ts # 连接邮件服务器的会话信息 +| |---- Folder.ts # 邮箱管理 +| |---- Message.ts # 邮件实体类 +| |---- MimeBodyPart.ts # HTML内嵌图片实体 +| |---- MimeMessage.ts # 邮件实体 +| |---- MimeMultipart.ts # imap邮件实体 +| |---- Properties.ts # 连接邮件服务器的会话信息 +| |---- RecipientType.ts # 收件人类型 +| |---- ResponseCode.ts # smtp服务器响应码 +| |---- SocketUtil.ts # socket工具 +| |---- Store.ts # 邮件接收、管理 +| |---- TransPort.ts # 邮件发送 + |---- GlobalContext.ts # GlobalContext替代globalThis +| |---- Constant.ts 常量 +| |---- MailLogger.ts 日志工具 +| |---- Uft7Base64.ts utf7转base64工具 +| |---- Utf7Util.ts utf7编解码工具 +| |---- Util.ts 工具 +| |---- index.ets # 对外接口 +| |---- README_zh.md # 安装使用方法 +```` + +## 贡献代码 + +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc/ohos_mail/issues)给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-tpc/ohos_mail/pulls) +。 + +## 开源协议 + +本项目基于 [Eclipse Public License version 2.0](https://gitee.com/openharmony-tpc/ohos_mail/blob/master/LICENSE-EPL-2.0-GPL-2.0-with-classpath-exception) ,请自由地享受和参与开源。 + +## 相关项目 + +- [emlformat](https://github.com/papnkukn/eml-format) —— 用于解析和构建EML文件的纯Node.js库,即RFC 822中描述的电子邮件格式。 +- [emailjs-utf7](https://github.com/emailjs/emailjs-utf7) —— 将JavaScript(Unicode/UCS-2)字符串编码和解码为UTF-7 ASCII字符串。 +- [emailjs-base64](https://github.com/emailjs/emailjs-base64) —— Base64对字符串和类型化数组进行编码。 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index edf7ceb1b7347b4fd7d78277bda748c8e1d53e68..b182e6326e326c42ee2e110e3eb37ab5475de69f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -20,7 +20,7 @@ import router from '@ohos.router' struct Index { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { - Button("smtp protocol") + Button($r('app.string.smtp_protocol')) .backgroundColor(Color.Grey) .fontSize("18fp") .fontColor(Color.White) @@ -33,7 +33,7 @@ struct Index { url: 'pages/smtp' }) }) - Button("pop3 protocol") + Button($r('app.string.pop3_protocol')) .backgroundColor(Color.Grey) .fontSize("18fp") .fontColor(Color.White) @@ -46,7 +46,7 @@ struct Index { url: 'pages/pop' }) }) - Button("imap protocol") + Button($r('app.string.imap_protocol')) .backgroundColor(Color.Grey) .fontSize("18fp") .fontColor(Color.White) @@ -59,7 +59,7 @@ struct Index { url: 'pages/imap' }) }) - Button("Email parsing") + Button($r('app.string.Parse_Email')) .backgroundColor(Color.Grey) .fontSize("18fp") .fontColor(Color.White) @@ -72,7 +72,7 @@ struct Index { url: 'pages/mailParseAndBuild' }) }) - Button("mimeType") + Button($r('app.string.mimeType')) .backgroundColor(Color.Grey) .fontSize("18fp") .fontColor(Color.White) diff --git a/entry/src/main/ets/pages/imap.ets b/entry/src/main/ets/pages/imap.ets index 32f863dce83ef1483d00dc8091cfdf853a2b108f..5453e9b898bf9b4324ed35e211f6f3ad15bff349 100644 --- a/entry/src/main/ets/pages/imap.ets +++ b/entry/src/main/ets/pages/imap.ets @@ -73,7 +73,7 @@ struct Imap { ListItem() { Row() { Column() { - Text("Please select an email address") + Text($r('app.string.Please_select_an_email_address')) .fontSize("16fp") .margin({ top: "2%" }) @@ -104,7 +104,7 @@ struct Imap { } Row() { - Text("Enable SSL") + Text($r('app.string.Enable_SSL')) .fontSize("16fp") .margin({ left: "20%" }) @@ -125,54 +125,54 @@ struct Imap { ListItem() { Column({ space: 12 }) { - Text('Delivery server') + Text($r('app.string.Receiving_server')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.hostReceive, placeholder: 'Please enter the recipient server address' }) + TextInput({ text: this.hostReceive, placeholder: $r('app.string.Please_enter_the_Receiving_server') }) .height(60) .fontSize(18) .onChange((value: string) => { this.hostReceive = value }) - Text('Receive server port') + Text($r('app.string.Receiving_server_port')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.portReceive.toString(), placeholder: 'Please enter the port of the receiving server' }) + TextInput({ text: this.portReceive.toString(), placeholder: $r('app.string.Please_enter_the_Receiving_server_port') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.portReceive = Number(value).valueOf() }) - Text('Receiving email') + Text($r('app.string.Receive_Email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.from, placeholder: 'Please enter the recipient email address' }) + TextInput({ text: this.from, placeholder: $r('app.string.Please_enter_the_Receive_Email') }) .height(60) .fontSize(18) .onChange((value: string) => { this.from = value }) - Text('Email authorization code for receiving emails') + Text($r('app.string.Recipient_email_authorization_code')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.authorizationCode, placeholder: 'Please enter the recipient email authorization code' }) + TextInput({ text: this.authorizationCode, placeholder: $r('app.string.Please_enter_the_Recipient_email_authorization_code') }) .height(60) .fontSize(18) .onChange((value: string) => { this.authorizationCode = value }) - Text('Need to read the index of the email') + Text($r('app.string.Index_of_email_to_read')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.readMsgIndex + "", placeholder: 'Need to read the index of the email' }) + TextInput({ text: this.readMsgIndex + "", placeholder: $r('app.string.Index_of_email_to_read') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.readMsgIndex = Number.parseInt(value) }) - Button('Receiving Mail', { type: ButtonType.Normal }) + Button($r('app.string.Receive_Email') , { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -213,11 +213,11 @@ struct Imap { let msg = messages[this.readMsgIndex-1] msg.getAllHeaders(async (success:boolean, msg: Message) => { if (success) { - this.parseResult += 'Headers ' + '\r\n' - + 'Sender: ' + msg.getFrom()[0] + "\r\n" - + 'Recipient: ' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" - + 'Theme: ' + msg.getSubject() + "\r\n" - + 'Date: ' + msg.getSentDate() + this.parseResult += getContext().resourceManager.getStringByNameSync("Headers") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Sender") + msg.getFrom()[0] + "\r\n" + + getContext().resourceManager.getStringByNameSync("Recipient") + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" + + getContext().resourceManager.getStringByNameSync("Subject") + msg.getSubject() + "\r\n" + + getContext().resourceManager.getStringByNameSync("Date") + msg.getSentDate() + "\r\n------------------------------------\r\n\r\n" } @@ -227,11 +227,11 @@ struct Imap { try { let textBody = await mime.syncGetText() - this.parseResult += 'main body ' + '\r\n' - + 'Data: ' + textBody.getContent() + "\r\n" - + 'CharSet: ' + textBody.getCharSet() + "\r\n" - + 'MimeType: ' + textBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + textBody.getTransferEncoding() + this.parseResult += getContext().resourceManager.getStringByNameSync("main_body") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + textBody.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + textBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType")+ textBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + textBody.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" } catch (err) { MailLogger.info('ohos_mail-- sync getText fail:' + err) @@ -239,11 +239,11 @@ struct Imap { try { let htmlBody = await mime.syncGetHtml() - this.parseResult += 'Html ' + '\r\n' - + 'Data: ' + htmlBody.getContent() + "\r\n" - + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" - + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + htmlBody.getTransferEncoding() + this.parseResult += getContext().resourceManager.getStringByNameSync("Html") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + htmlBody.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + htmlBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType")+ htmlBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + htmlBody.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" } catch (err) { MailLogger.info('ohos_mail-- sync getHtml fail:' + err) @@ -251,11 +251,11 @@ struct Imap { try { let calendarBody = await mime.syncGetCalendar() - this.parseResult += 'Calendar ' + '\r\n' - + 'Data: ' + calendarBody.getContent() + "\r\n" - + 'CharSet: ' + calendarBody.getCharSet() + "\r\n" - + 'MimeType: ' + calendarBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + calendarBody.getTransferEncoding() + this.parseResult += getContext().resourceManager.getStringByNameSync("Calendar") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + calendarBody.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + calendarBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + calendarBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + calendarBody.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" } catch (err) { MailLogger.info('ohos_mail-- sync getCalendar fail:' + err) @@ -267,11 +267,11 @@ struct Imap { for (let i = 0; i < attachCount; i++) { try { let attachBody = mime.getAttachment(i) - this.parseResult += 'annex ' + i + '\r\n' - + 'FileName: ' + attachBody.getFileName() + "\r\n" - + 'CharSet: ' + attachBody.getCharSet() + "\r\n" - + 'MimeType: ' + attachBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + attachBody.getEncoding() + this.parseResult += getContext().resourceManager.getStringByNameSync("annex") + i + '\r\n' + + getContext().resourceManager.getStringByNameSync("FileName") + attachBody.getFileName() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + attachBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + attachBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + attachBody.getEncoding() + "\r\n------------------------------------\r\n\r\n" //接收附件数据的文件 let attachmentFilePath = this.filesPath + "/" + i + ".txt"; @@ -333,7 +333,7 @@ struct Imap { }) - Button('Receiving Mail(taskpool)', { type: ButtonType.Normal }) + Button($r('app.string.Receive_Mail_taskpool'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -347,7 +347,7 @@ struct Imap { }); }) - Text("Email Content\r\n\r\n" + this.parseResult) + Text(getContext().resourceManager.getStringByNameSync("Email_content")+"\r\n\r\n" + this.parseResult) .width('90%') .fontSize(18) .padding({ left: 10 }) @@ -362,7 +362,7 @@ struct Imap { } ListItem() { - Text('update') + Text($r('app.string.update')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -371,7 +371,7 @@ struct Imap { ListItem() { Column({ space: 12 }) { - Button('Update email(Get the last 10 emails)', { type: ButtonType.Normal }) + Button($r('app.string.Update_email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -413,10 +413,10 @@ struct Imap { messages[i].getAllHeaders((success:boolean, result:ESObject) => { if (success) { this.msgList += i + 1 + "\r\n" - + 'Sender:' + result.getFrom()[0] + Constant.LINEFEED + Constant.LINEFEED - + 'Theme:' + result.getSubject() + Constant.LINEFEED + Constant.LINEFEED - + 'Recipient: ' + JSON.stringify(result.getRecipients(RecipientType.TO)) + Constant.LINEFEED - + 'Date: ' + result.getSentDate() + Constant.LINEFEED + Constant.LINEFEED + + getContext().resourceManager.getStringByNameSync("Sender") + result.getFrom()[0] + Constant.LINEFEED + Constant.LINEFEED + + getContext().resourceManager.getStringByNameSync("Subject") + result.getSubject() + Constant.LINEFEED + Constant.LINEFEED + + getContext().resourceManager.getStringByNameSync("Recipient") + JSON.stringify(result.getRecipients(RecipientType.TO)) + Constant.LINEFEED + + getContext().resourceManager.getStringByNameSync("Date") + result.getSentDate() + Constant.LINEFEED + Constant.LINEFEED + "-----------------------------------------------------------------------\r\n\r\n" } resolve('') @@ -442,7 +442,7 @@ struct Imap { }) }) - Text("Email Content\r\n" + this.msgList) + Text(getContext().resourceManager.getStringByNameSync("Email_content")+"\r\n" + this.msgList) .width('90%') .fontSize(20) .padding({ left: 10 }) @@ -459,7 +459,7 @@ struct Imap { } ListItem() { - Text('deleted items') + Text($r('app.string.Delete_mail')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -468,17 +468,17 @@ struct Imap { ListItem() { Column({ space: 12 }) { - Text('To delete the email number') + Text($r('app.string.The_number_of_the_mail_to_delete')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.deleteMsgIndex + "", placeholder: 'To delete the email number' }) + TextInput({ text: this.deleteMsgIndex + "", placeholder: $r('app.string.The_number_of_the_mail_to_delete') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.deleteMsgIndex = Number.parseInt(value) }) - Button('deleted items', { type: ButtonType.Normal }) + Button($r('app.string.Delete_mail'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -519,19 +519,19 @@ struct Imap { await folder.syncExpunge() MailLogger.info('ohos_mail-- expunge success') prompt.showToast({ - message: "Delete successfully", + message:getContext().resourceManager.getStringByNameSync("Delete_successfully"), duration: 2500 }) } catch (err) { MailLogger.info('ohos_mail-- expunge fail: ' + err) prompt.showToast({ - message: "Delete failed" + err, + message: getContext().resourceManager.getStringByNameSync("Delete_failed") + err, duration: 2500 }) } return } - prompt.showToast({ message: "Delete failed:" + err, duration: 2000 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Delete_failed") + err, duration: 2000 }) store.close((success:boolean) => { if (success) { MailLogger.info('ohos_mail-- close imap success') @@ -541,7 +541,7 @@ struct Imap { }) }) } else { - prompt.showToast({ message: "This email does not exist", duration: 2000 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("This_email_does_not_exist"), duration: 2000 }) } }) } catch (err) { @@ -562,7 +562,7 @@ struct Imap { } ListItem() { - Text('move Mail') + Text($r('app.string.move_Mail')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -571,17 +571,17 @@ struct Imap { ListItem() { Column({ space: 12 }) { - Text('To move the email number') + Text($r('app.string.To_move_the_email_number')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.deleteMsgIndex + "", placeholder: 'To move the email number' }) + TextInput({ text: this.deleteMsgIndex + "", placeholder: $r('app.string.To_move_the_email_number') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.moveMsgIndex = Number.parseInt(value) }) - Button('move Mail', { type: ButtonType.Normal }) + Button($r('app.string.move_Mail'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -622,7 +622,7 @@ struct Imap { let messages = folder.getMessages() await folder.syncMoveMessages([messages[this.moveMsgIndex-1]], new Folder('Drafts')) MailLogger.info('ohos_mail-- moveMessages success') - prompt.showToast({ message: "Move successful", duration: 4000 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Move_successful"), duration: 4000 }) await store.syncClose() } else { MailLogger.info('ohos_mail-- imap open folder fail:' + err) @@ -686,11 +686,11 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f let msg = messages[index-1] msg.getAllHeaders(async (success:boolean, msg: Message) => { if (success) { - parseResult += 'Headers ' + '\r\n' - + 'Sender: ' + msg.getFrom()[0] + "\r\n" - + 'Recipient: ' + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" - + 'Theme: ' + msg.getSubject() + "\r\n" - + 'Date: ' + msg.getSentDate() + parseResult +=getContext().resourceManager.getStringByNameSync("Headers") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Sender") + msg.getFrom()[0] + "\r\n" + + getContext().resourceManager.getStringByNameSync("Recipient") + JSON.stringify(msg.getRecipients(RecipientType.TO)) + "\r\n" + + getContext().resourceManager.getStringByNameSync("Subject") + msg.getSubject() + "\r\n" + + getContext().resourceManager.getStringByNameSync("Date") + msg.getSentDate() + "\r\n------------------------------------\r\n\r\n" } @@ -700,11 +700,11 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f try { let textBody = await mime.syncGetText() - parseResult += 'Main Body ' + '\r\n' - + 'Data: ' + textBody.getContent() + "\r\n" - + 'CharSet: ' + textBody.getCharSet() + "\r\n" - + 'MimeType: ' + textBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + textBody.getTransferEncoding() + parseResult += getContext().resourceManager.getStringByNameSync("main_body") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + textBody.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + textBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + textBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + textBody.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" } catch (err) { MailLogger.info('ohos_mail-- sync getText fail:' + err) @@ -712,11 +712,11 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f try { let htmlBody = await mime.syncGetHtml() - parseResult += 'Html ' + '\r\n' - + 'Data: ' + htmlBody.getContent() + "\r\n" - + 'CharSet: ' + htmlBody.getCharSet() + "\r\n" - + 'MimeType: ' + htmlBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + htmlBody.getTransferEncoding() + parseResult += getContext().resourceManager.getStringByNameSync("Html") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + htmlBody.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + htmlBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + htmlBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + htmlBody.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" MailLogger.info('ohos_mail-- data** :' + htmlBody.getContent()) } catch (err) { @@ -725,11 +725,11 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f try { let calendar = await mime.syncGetCalendar() - parseResult += 'Calendar ' + '\r\n' - + 'Data: ' + calendar.getContent() + "\r\n" - + 'CharSet: ' + calendar.getCharSet() + "\r\n" - + 'MimeType: ' + calendar.getMimeType() + "\r\n" - + 'TransferEncoding: ' + calendar.getTransferEncoding() + parseResult += getContext().resourceManager.getStringByNameSync("Calendar") + '\r\n' + + getContext().resourceManager.getStringByNameSync("Data") + calendar.getContent() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + calendar.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + calendar.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + calendar.getTransferEncoding() + "\r\n------------------------------------\r\n\r\n" } catch (err) { MailLogger.info('ohos_mail-- sync getCalendar fail:' + err) @@ -742,11 +742,11 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f for (let i = 0; i < attachCount; i++) { try { let attachBody = mime.getAttachment(i) - parseResult += 'annex ' + i + '\r\n' - + 'FileName: ' + attachBody.getFileName() + "\r\n" - + 'CharSet: ' + attachBody.getCharSet() + "\r\n" - + 'MimeType: ' + attachBody.getMimeType() + "\r\n" - + 'TransferEncoding: ' + attachBody.getEncoding() + parseResult += getContext().resourceManager.getStringByNameSync("annex") + i + '\r\n' + + getContext().resourceManager.getStringByNameSync("FileName") + attachBody.getFileName() + "\r\n" + + getContext().resourceManager.getStringByNameSync("CharSet") + attachBody.getCharSet() + "\r\n" + + getContext().resourceManager.getStringByNameSync("MimeType") + attachBody.getMimeType() + "\r\n" + + getContext().resourceManager.getStringByNameSync("TransferEncoding") + attachBody.getEncoding() + "\r\n------------------------------------\r\n\r\n" //接收附件数据的文件 diff --git a/entry/src/main/ets/pages/mailParseAndBuild.ets b/entry/src/main/ets/pages/mailParseAndBuild.ets index 6fd555ea4c4923d9f9af8ac720784b9341497c41..86f4efb752bd26b0063cabc089c4e3644e25ed13 100644 --- a/entry/src/main/ets/pages/mailParseAndBuild.ets +++ b/entry/src/main/ets/pages/mailParseAndBuild.ets @@ -36,8 +36,8 @@ struct mailParseAndBuild { private to: string[] = ["xx@sina.com", "xx@hoperun.com"]; private Cc: string[] = ["xx@qq.com"]; private Bc: string[] = ["xx@qq.com"]; - private subject: string = "Test email sending"; - private text: string = "This is a test email"; + private subject: string = getContext().resourceManager.getStringByNameSync("Test_email_sending"); + private text: string = getContext().resourceManager.getStringByNameSync("This_is_a_test_email"); private filesPath:string = ''; @@ -56,7 +56,7 @@ struct mailParseAndBuild { List({ space: 20, initialIndex: 0 }) { ListItem() { - Text('Email parsing and construction') + Text($r('app.string.Parse_and_Construct_Email')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -65,7 +65,7 @@ struct mailParseAndBuild { ListItem() { Column({ space: 12 }) { - Button('Email parsing', { type: ButtonType.Normal }) + Button($r('app.string.Parse_Email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -76,18 +76,18 @@ struct mailParseAndBuild { MailLogger.info('ohos_mail-- parser file result----:' + JSON.stringify(result)); this.pathParseResult = JSON.stringify(JSON.parse(JSON.stringify(result)), null, 4) } else { - prompt.showToast({ message: "parsing failed:" + JSON.stringify(result), duration: 3000 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("parsing_failed") + JSON.stringify(result), duration: 3000 }) MailLogger.info('ohos_mail-- parser file fail : ' + JSON.stringify(result)); } }); }) - Text('filename:sample.eml') + Text($r('app.string.filename_sample_eml')) .fontColor('#333333') .fontSize(18) .fontWeight(700) - Text('parsing results : ' + this.pathParseResult) + Text(getContext().resourceManager.getStringByNameSync("parsing_results") + this.pathParseResult) .fontColor('#ff206adf') .fontSize(16) .fontWeight(700) @@ -101,7 +101,7 @@ struct mailParseAndBuild { ListItem() { Column({ space: 12 }) { - Button('Email construction', { type: ButtonType.Normal }) + Button($r('app.string.Email_construction'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -142,7 +142,7 @@ struct mailParseAndBuild { this.buildResult = utfStr }) - Text('construction resules : \r\n' + this.buildResult) + Text(getContext().resourceManager.getStringByNameSync("construction_resules") +'\r\n' + this.buildResult) .fontColor('#ff206adf') .fontSize(16) .fontWeight(700) diff --git a/entry/src/main/ets/pages/mimeType.ets b/entry/src/main/ets/pages/mimeType.ets index d49a53ac27e5e5fdadec5fb98733f3d5000be121..a365029ab5519c97cab8dcbd3798ad8088a1db60 100644 --- a/entry/src/main/ets/pages/mimeType.ets +++ b/entry/src/main/ets/pages/mimeType.ets @@ -40,7 +40,7 @@ struct MimeType { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { List({ space: 20, initialIndex: 0 }) { ListItem() { - Text('Detecting file MIME type') + Text($r('app.string.Test_MIME_Type')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -49,13 +49,13 @@ struct MimeType { ListItem() { Column({ space: 12 }) { - Button('test otherfile mimetype', { type: ButtonType.Normal }) + Button($r('app.string.test_otherfile_mimetype'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.otherFileResult = 'Resolving...' + this.otherFileResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.otherFileResult = "\r\n" + "mimeType bat : " + MimeTypeDetector.detectMimeType(this.path + "/logdemo.bat") + "\r\n" + "mimeType properties : " + MimeTypeDetector.detectMimeType(this.path + "/logdemo.properties") + "\r\n" @@ -67,7 +67,7 @@ struct MimeType { }) .align(Alignment.Start) - Text('filename:\r\nlogdemo.bat\r\nlogdemo.properties\r\nafpfile.afp') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nlogdemo.bat\r\nlogdemo.properties\r\nafpfile.afp') .fontColor('#333333') .fontSize(16) @@ -90,7 +90,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.mimetypeResult = 'Resolving...' + this.mimetypeResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.mimetypeResult = "\r\n" + "mimeType java : " + MimeTypeDetector.detectMimeType("logdemo.java") + "\r\n" @@ -111,7 +111,7 @@ struct MimeType { } }) - Text('filename:\r\nlogdemo.java\r\nlogdemo.mp3\r\nlogdemo.zip\r\nlogdemo.jar\r\nlogdemo.rar\r\nlogdemo.mp4\r\nlogdemo.tar.gz\r\nlogdemo.png\r\nlogdemo.gif\r\nlogdemo.img\r\nlogdemo.svg\r\nlogdemo.xml') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nlogdemo.java\r\nlogdemo.mp3\r\nlogdemo.zip\r\nlogdemo.jar\r\nlogdemo.rar\r\nlogdemo.mp4\r\nlogdemo.tar.gz\r\nlogdemo.png\r\nlogdemo.gif\r\nlogdemo.img\r\nlogdemo.svg\r\nlogdemo.xml') .fontColor('#333333') .fontSize(16) @@ -134,7 +134,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.globLiteralResult = 'Resolving...' + this.globLiteralResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.globLiteralResult = "\r\n" + "mimeType makefile : " + MimeTypeDetector.detectMimeType("makefile") + "\r\n" @@ -145,11 +145,11 @@ struct MimeType { } }) - Text('filename:\r\nmakefile\r\nMakefile') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nmakefile\r\nMakefile') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.globLiteralResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.globLiteralResult) .fontColor('#ff206adf') .fontSize(16) } @@ -168,7 +168,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.globExtensionResult = 'Resolving...' + this.globExtensionResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.globExtensionResult = "\r\n" + "mimeType txt : " + MimeTypeDetector.detectMimeType("abc.txt") + "\r\n" @@ -185,11 +185,11 @@ struct MimeType { } }) - Text('filename:\r\nabc.txt\r\nx.cur\r\nwinmail.dat\r\nabc.mm\r\nabc.anim5\r\nabc.animj\r\nREADME.Z\r\nt.pst') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nabc.txt\r\nx.cur\r\nwinmail.dat\r\nabc.mm\r\nabc.anim5\r\nabc.animj\r\nREADME.Z\r\nt.pst') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.globExtensionResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.globExtensionResult) .fontColor('#ff206adf') .fontSize(16) } @@ -208,7 +208,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.globFilenameResult = 'Resolving...' + this.globFilenameResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.globFilenameResult = "\r\n" + "mimeType README : " + MimeTypeDetector.detectMimeType("README") + "\r\n" @@ -222,11 +222,11 @@ struct MimeType { } }) - Text('filename:\r\nREADME\r\nREADMEFILE\r\nREADMEanim3\r\nREADME.log\r\nREADME.file') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nREADME\r\nREADMEFILE\r\nREADMEanim3\r\nREADME.log\r\nREADME.file') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.globFilenameResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.globFilenameResult) .fontColor('#ff206adf') .fontSize(16) } @@ -245,7 +245,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.octetStreamResult = 'Resolving...' + this.octetStreamResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.octetStreamResult = "\r\n" + "mimeType empty : " + MimeTypeDetector.detectMimeType(this.path + "/empty") + "\r\n" @@ -256,11 +256,11 @@ struct MimeType { } }) - Text('filename:\r\nempty\r\noctet-stream') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nempty\r\noctet-stream') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.octetStreamResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.octetStreamResult) .fontColor('#ff206adf') .fontSize(16) } @@ -279,7 +279,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.magicAndMagicIndentResult = 'Resolving...' + this.magicAndMagicIndentResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.magicAndMagicIndentResult = "\r\n" + "mimeType a : " + MimeTypeDetector.detectMimeType(this.path + "/a") + "\r\n" @@ -290,11 +290,11 @@ struct MimeType { } }) - Text('filename:\r\na\r\ne[xml]') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\na\r\ne[xml]') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.magicAndMagicIndentResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.magicAndMagicIndentResult) .fontColor('#ff206adf') .fontSize(16) } @@ -313,7 +313,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.textResult = 'Resolving...' + this.textResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.textResult = "\r\n" + "mimeType plaintext : " + MimeTypeDetector.detectMimeType(this.path + "/plaintext") @@ -323,11 +323,11 @@ struct MimeType { } }) - Text('filename:plaintext') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'plaintext') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.textResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.textResult) .fontColor('#ff206adf') .fontSize(16) } @@ -346,7 +346,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.respectsMagicFileOrderingAndMPEG4Result = 'Resolving...' + this.respectsMagicFileOrderingAndMPEG4Result = getContext().resourceManager.getStringByNameSync("Resolving") try { this.respectsMagicFileOrderingAndMPEG4Result = "\r\n" + "mimeType ogv-video-header : " + MimeTypeDetector.detectMimeType(this.path + "/ogv-video-header") + "\r\n" @@ -358,11 +358,11 @@ struct MimeType { } }) - Text('filename:\r\nogv-video-header\r\nmp4v1-video-header\r\nmp4v2-video-header') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'\r\nogv-video-header\r\nmp4v1-video-header\r\nmp4v2-video-header') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.respectsMagicFileOrderingAndMPEG4Result) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.respectsMagicFileOrderingAndMPEG4Result) .fontColor('#ff206adf') .fontSize(16) } @@ -381,7 +381,7 @@ struct MimeType { .height(60) .backgroundColor('#12939f') .onClick((event: ClickEvent) => { - this.emptyFileAndFileResult = 'Resolving...' + this.emptyFileAndFileResult = getContext().resourceManager.getStringByNameSync("Resolving") try { this.emptyFileAndFileResult = "\r\n" + " mime-type-test.weird file not exist : " + MimeTypeDetector.detectMimeType("mime-type-test.weird") + "\r\n" @@ -392,11 +392,11 @@ struct MimeType { } }) - Text('filename:mime-type-test.weird') + Text(getContext().resourceManager.getStringByNameSync("FileName")+'mime-type-test.weird') .fontColor('#333333') .fontSize(16) - Text('Resolving result : ' + this.emptyFileAndFileResult) + Text(getContext().resourceManager.getStringByNameSync("Resolving_result") + this.emptyFileAndFileResult) .fontColor('#ff206adf') .fontSize(16) } diff --git a/entry/src/main/ets/pages/pop.ets b/entry/src/main/ets/pages/pop.ets index b44e79e939e1ce405bace7a2a67a506dfdfd56b3..d221e13cb9a965238b8eeb9b7ee8cdafde03328e 100644 --- a/entry/src/main/ets/pages/pop.ets +++ b/entry/src/main/ets/pages/pop.ets @@ -58,7 +58,7 @@ struct Pop { ListItem() { Row() { Column() { - Text("Please select an email address") + Text($r('app.string.Please_select_an_email_address')) .fontSize("16fp") .margin({ top: "2%" }) @@ -88,7 +88,7 @@ struct Pop { }) } Row() { - Text("Enable SSL") + Text($r('app.string.Enable_SSL')) .fontSize("16fp") .margin({ left: "20%" }) @@ -108,54 +108,54 @@ struct Pop { ListItem() { Column({ space: 12 }) { - Text('Delivery server') + Text($r('app.string.Recipient_email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.hostReceive, placeholder: 'Please enter the recipient server address' }) + TextInput({ text: this.hostReceive, placeholder: $r('app.string.Please_enter_the_Recipient_email') }) .height(60) .fontSize(18) .onChange((value: string) => { this.hostReceive = value }) - Text('Receive server port') + Text($r('app.string.Receiving_server_port')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.portReceive.toString(), placeholder: 'Please enter the port of the receiving server' }) + TextInput({ text: this.portReceive.toString(), placeholder: $r('app.string.Please_enter_the_Receiving_server_port') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.portReceive = Number(value).valueOf() }) - Text('Receiving email') + Text($r('app.string.Recipient_email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.from, placeholder: 'Please enter the recipient email address' }) + TextInput({ text: this.from, placeholder: $r('app.string.Please_enter_the_Recipient_email') }) .height(60) .fontSize(18) .onChange((value: string) => { this.from = value }) - Text('Email authorization code for receiving emails') + Text($r('app.string.Recipient_email_authorization_code')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.authorizationCode, placeholder: 'Please enter the recipient email authorization code' }) + TextInput({ text: this.authorizationCode, placeholder: $r('app.string.Please_enter_the_Recipient_email_authorization_code') }) .height(60) .fontSize(18) .onChange((value: string) => { this.authorizationCode = value }) - Text('Need to read the index of the email') + Text($r('app.string.Index_of_email_to_read')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.readMsgIndex + "", placeholder: 'Need to read the index of the email' }) + TextInput({ text: this.readMsgIndex + "", placeholder: $r('app.string.Index_of_email_to_read') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.readMsgIndex = Number.parseInt(value) }) - Button('Receiving Mail', { type: ButtonType.Normal }) + Button($r('app.string.Receive_Email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -187,17 +187,17 @@ struct Pop { MailLogger.info("ohos_mail") let message = await msg.syncGetContent() let result = message as Message - this.parseResult = 'Sender: ' + result.getFrom()[0] + "\r\n\r\n" - + 'Theme: ' + result.getSubject() + "\r\n\r\n" - + 'Recipient: ' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" - + 'Main Body: ' + result.getText() + "\r\n\r\n" - + 'HTML: ' + result.getHtml() + "\r\n\r\n" + this.parseResult = getContext().resourceManager.getStringByNameSync("Sender")+ result.getFrom()[0] + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Subject") + result.getSubject() + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Recipient")+ result.getRecipients(RecipientType.TO) + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("main_body")+ result.getText() + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Html")+ result.getHtml() + "\r\n\r\n" let files = result.getFiles() if (!!files) { let length = files.length for (let i = 0; i < length; i++) { - this.parseResult += "annex " + (i + 1) + ": " + files[i].getFileName() + "\r\n" + this.parseResult += getContext().resourceManager.getStringByNameSync("annex") + (i + 1) + ": " + files[i].getFileName() + "\r\n" + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n" + " Content-Type:" + files[i].getMimeType() + "\r\n" + " Attachment content length:" + files[i].getData().length + "\r\n\r\n" @@ -226,7 +226,7 @@ struct Pop { }) }) - Button('Receiving Mail(taskpool)', { type: ButtonType.Normal }) + Button($r('app.string.Receive_Mail_taskpool'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -241,7 +241,7 @@ struct Pop { }); }) - Text("Email Content\r\n\r\n" + this.parseResult) + Text(getContext().resourceManager.getStringByNameSync("Email_content")+"Email Content\r\n\r\n" + this.parseResult) .width('90%') .fontSize(20) .padding({ left: 10 }) @@ -257,7 +257,7 @@ struct Pop { ListItem() { - Text('update') + Text($r('app.string.update')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -266,7 +266,7 @@ struct Pop { ListItem() { Column({ space: 12 }) { - Button('Update email(Get the last 10 emails)', { type: ButtonType.Normal }) + Button($r('app.string.Update_email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -304,10 +304,10 @@ struct Pop { await new Promise((resolve, reject) => { messages[i].getAllHeaders((success:boolean, result:ESObject) => { if(success){ - this.msgList += i + 1 + ' Sender:' + result.getFrom()[0] + Constant.LINEFEED + Constant.LINEFEED - + ' Theme:' + result.getSubject() + Constant.LINEFEED + Constant.LINEFEED - + 'Recipient: ' + JSON.stringify(result.getRecipients(RecipientType.TO)) + Constant.LINEFEED - + 'Date: ' + result.getSentDate() + Constant.LINEFEED + Constant.LINEFEED + this.msgList += i + 1 + getContext().resourceManager.getStringByNameSync("Sender") + result.getFrom()[0] + Constant.LINEFEED + Constant.LINEFEED + +getContext().resourceManager.getStringByNameSync("Subject") + result.getSubject() + Constant.LINEFEED + Constant.LINEFEED + +getContext().resourceManager.getStringByNameSync("Recipient") + JSON.stringify(result.getRecipients(RecipientType.TO)) + Constant.LINEFEED + +getContext().resourceManager.getStringByNameSync("Date") + result.getSentDate() + Constant.LINEFEED + Constant.LINEFEED + "-----------------------------------------------------------------------\r\n\r\n" } resolve('') @@ -332,7 +332,7 @@ struct Pop { }) }) - Text("Email Content\r\n\r\n" + this.msgList) + Text(getContext().resourceManager.getStringByNameSync("Email_content")+"\r\n\r\n" + this.msgList) .width('90%') .fontSize(20) .padding({ left: 10 }) @@ -349,7 +349,7 @@ struct Pop { ListItem() { - Text('deleted items') + Text($r('app.string.Delete_mail')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -358,17 +358,17 @@ struct Pop { ListItem() { Column({ space: 12 }) { - Text('To delete the email number') + Text($r('app.string.The_number_of_the_mail_to_delete')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.deleteMsgIndex + "", placeholder: 'To delete the email number' }) + TextInput({ text: this.deleteMsgIndex + "", placeholder: $r('app.string.The_number_of_the_mail_to_delete') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.deleteMsgIndex = Number.parseInt(value) }) - Button('deleted items', { type: ButtonType.Normal }) + Button($r('app.string.Delete_mail'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -406,14 +406,14 @@ struct Pop { try { await folder.syncExpunge() MailLogger.info('ohos_mail-- expunge success') - prompt.showToast({ message: "Delete successfully", duration: 2500 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Delete_successfully"), duration: 2500 }) } catch (err) { MailLogger.info('ohos_mail-- expunge fail: ' + err) - prompt.showToast({ message: "Delete failed" + err, duration: 2500 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Delete_failed") + err, duration: 2500 }) } return } - prompt.showToast({ message: "Delete failed:" + err, duration: 2500 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Delete_failed") + err, duration: 2500 }) store.close((success:boolean) => { if (success) { MailLogger.info('ohos_mail-- close pop3 success') @@ -423,7 +423,7 @@ struct Pop { }) }) } else { - prompt.showToast({ message: "不存在此邮件", duration: 2000 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("This_email_does_not_exist") , duration: 2000 }) } }) } catch (err) { @@ -480,16 +480,16 @@ async function asyncTask(index:number, hostReceive:string, portReceive:number, f let result = message as Message parseResult = 'Sender: ' + result.getFrom()[0] + "\r\n\r\n" - + 'Theme: ' + result.getSubject() + "\r\n\r\n" - + 'recipient: ' + result.getRecipients(RecipientType.TO) + "\r\n\r\n" - + 'Main Body: ' + result.getText() + "\r\n\r\n" - + 'HTML: ' + result.getHtml() + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Subject") + result.getSubject() + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Recipient") + result.getRecipients(RecipientType.TO) + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("main_body") + result.getText() + "\r\n\r\n" + + getContext().resourceManager.getStringByNameSync("Html")+ result.getHtml() + "\r\n\r\n" let files = result.getFiles() if (!!files) { let length = files.length for (let i = 0; i < length; i++) { - parseResult += "annex " + (i + 1) + ": " + files[i].getFileName() + "\r\n\r\n" + parseResult += getContext().resourceManager.getStringByNameSync("annex") + (i + 1) + ": " + files[i].getFileName() + "\r\n\r\n" + " Content-Transfer-Encoding:" + files[i].getEncoding() + "\r\n\r\n" + " Content-Type:" + files[i].getMimeType() + "\r\n\r\n" + " Attachment content length:" + files[i].getData().length + "\r\n\r\n" diff --git a/entry/src/main/ets/pages/smtp.ets b/entry/src/main/ets/pages/smtp.ets index 008a43089d54b4c00d45c0543f4650b5581847ba..b7749b12c5f9abb6ef785f2954115fa07aa8b1f8 100644 --- a/entry/src/main/ets/pages/smtp.ets +++ b/entry/src/main/ets/pages/smtp.ets @@ -81,7 +81,7 @@ struct Smtp { ListItem() { Row() { Column() { - Text("Please select an email address") + Text($r('app.string.Please_select_an_email_address')) .fontSize("16fp") .margin({ top: "2%" }) @@ -115,7 +115,7 @@ struct Smtp { } Row() { - Text("Enable SSL") + Text($r('app.string.Enable_SSL')) .fontSize("16fp") .margin({ left: "20%" }) @@ -139,89 +139,89 @@ struct Smtp { ListItem() { Column({ space: 12 }) { - Text('Sending server') + Text($r('app.string.Sending_server')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.host, placeholder: 'Please enter the sender server address' }) + TextInput({ text: this.host, placeholder: $r('app.string.Please_enter_the_Sending_server') }) .height(60) .fontSize(18) .onChange((value: string) => { this.host = value }) - Text('Sending server port') + Text($r('app.string.Sending_server_port')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.port.toString(), placeholder: 'Please enter the sender server port' }) + TextInput({ text: this.port.toString(), placeholder: $r('app.string.Please_enter_the_Sending_server_port') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.port = Number(value).valueOf() }) - Text('Sending email') + Text($r('app.string.Send_Email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.from, placeholder: 'Please enter the sending email address' }) + TextInput({ text: this.from, placeholder:$r('app.string.Please_enter_the_sending_email_address') }) .height(60) .fontSize(18) .onChange((value: string) => { this.from = value }) - Text('Email Authorization Code for Sending') + Text($r('app.string.Sender_email_authorization_code')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.authorizationCode, placeholder: 'Please enter the sender email authorization code' }) + TextInput({ text: this.authorizationCode, placeholder: $r('app.string.Please_enter_the_Sender_email_authorization_code')}) .height(60) .fontSize(18) .onChange((value: string) => { this.authorizationCode = value }) - Text('Receiving email') + Text($r('app.string.Receive_Email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.getRecipient(this.to), placeholder: 'Please enter the recipient email address, multiple email addresses separated' }) + TextInput({ text: this.getRecipient(this.to), placeholder: $r('app.string.Please_enter_the_recipient_email_address_multiple_email_addresses_separated') }) .height(60) .fontSize(18) .onChange((value: string) => { this.to = value.split(",") }) - Text('CC email') + Text($r('app.string.CC_email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.getRecipient(this.Cc), placeholder: 'Please enter the cc recipient\'s email address' }) + TextInput({ text: this.getRecipient(this.Cc), placeholder: $r('app.string.Please_ente_the_cc_recipients_email_address') }) .height(60) .fontSize(18) .onChange((value: string) => { this.Cc = value.split(",") }) - Text('Confidential delivery email') + Text($r('app.string.BCC_email')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.getRecipient(this.Bc), placeholder: 'Please enter the sender\'s email address' }) + TextInput({ text: this.getRecipient(this.Bc), placeholder: $r('app.string.Please_enter_the_BCC_email') }) .height(60) .fontSize(18) .onChange((value: string) => { this.Bc = value.split(",") }) - Text('Email Subject') + Text($r('app.string.Subject')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.subject, placeholder: 'Please enter the email subject' }) + TextInput({ text: this.subject, placeholder: $r('app.string.Please_enter_the_Subject')}) .height(60) .fontSize(18) .onChange((value: string) => { this.subject = value }) - Text('Email Text Content') + Text($r('app.string.Body')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.text, placeholder: 'Please enter the email text content' }) + TextInput({ text: this.text, placeholder: $r('app.string.Please_enter_the_Body') }) .height(60) .fontSize(18) .onChange((value: string) => { this.text = value }) - Button('send mail', { type: ButtonType.Normal }) + Button($r('app.string.Send_Email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -232,10 +232,10 @@ struct Smtp { let task = new taskpool.Task(asyncTask, this.host, this.port, this.from, this.to, this.Cc, this.Cc, this.authorizationCode, this.isSSL, this.ca); try { await taskpool.execute(task) - prompt.showToast({ message: "Successfully sent!", duration: 2500 }) + prompt.showToast({ message: getContext().resourceManager.getStringByNameSync("Sent_successfully"), duration: 2500 }) } catch (e) { prompt.showToast({ - message: "fail in send:" + JSON.stringify(e), + message: getContext().resourceManager.getStringByNameSync("Send_failure")+ JSON.stringify(e), duration: 2500 }) } @@ -249,7 +249,7 @@ struct Smtp { } ListItem() { - Text('Forward email') + Text($r('app.string.Forward')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -258,17 +258,17 @@ struct Smtp { ListItem() { Column({ space: 12 }) { - Text('Index of emails that need to be forwarded') + Text($r('app.string.Index_of_email_to_forward')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.frowardMsgIndex + "", placeholder: 'Index of emails that need to be forwarded' }) + TextInput({ text: this.frowardMsgIndex + "", placeholder: $r('app.string.Index_of_email_to_forward') }) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.frowardMsgIndex = Number.parseInt(value) }) - Button('Forward email', { type: ButtonType.Normal }) + Button($r('app.string.Forward'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -321,7 +321,7 @@ struct Smtp { try { let attachBody = mime.getAttachment(i) //接收附件数据的文件 - let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-annex-" + i + ".txt"; + let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-"+getContext().resourceManager.getStringByNameSync("annex")+"-" + i + ".txt"; let attachmentFile = fs.openSync( attachmentFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.APPEND @@ -362,7 +362,7 @@ struct Smtp { try { let attachBody = mime.getInlineAttachment(i) //接收附件数据的文件 - let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-Inline attachments-" + i + ".txt"; + let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-"+getContext().resourceManager.getStringByNameSync("Inline_attachments")+"-" + i + ".txt"; let attachmentFile = fs.openSync( attachmentFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.APPEND @@ -413,13 +413,13 @@ struct Smtp { mimeMessage.setRecipients(RecipientType.BCC, this.Bc) mimeMessage.setSubject("forward:" + message.getSubject()) - let text = "Forwarding test\r\n\r\n\r\n" - + "------------------ original message ------------------\r\n" - + "Sender: " + message.getFrom()[0] + "\r\n" - + "Sending time: " + message.getSentDate() + "\r\n" + let text = getContext().resourceManager.getStringByNameSync("Forwarding_test")+"\r\n\r\n\r\n" + + "------------------ "+getContext().resourceManager.getStringByNameSync("original_email")+" ------------------\r\n" + + getContext().resourceManager.getStringByNameSync("Sender") + message.getFrom()[0] + "\r\n" + + getContext().resourceManager.getStringByNameSync("Sending_time") + message.getSentDate() + "\r\n" let to = message.getRecipients(RecipientType.TO) if (!!to) { - text += "recipient: " + text += getContext().resourceManager.getStringByNameSync("Recipient") for (let i = 0; i < to.length; i++) { if (i != to.length - 1) { text += to[i] + " , " @@ -429,10 +429,10 @@ struct Smtp { } } - text += "theme: " + message.getSubject() + "\r\n" + text += getContext().resourceManager.getStringByNameSync("Subject") + message.getSubject() + "\r\n" let cc = message.getRecipients(RecipientType.CC) if (!!cc) { - text += "make a copy for: " + text += getContext().resourceManager.getStringByNameSync("CC") for (let i = 0; i < cc.length; i++) { if (i != cc.length - 1) { text += cc[i] + " , " @@ -462,12 +462,12 @@ struct Smtp { if (!err) { MailLogger.info('ohos_mail-- send message success'); prompt.showToast({ - message: "Forwarding successful!", + message: getContext().resourceManager.getStringByNameSync("Forwarded_successfully"), duration: 2500 }) } else { prompt.showToast({ - message: "Forwarding failed:" + JSON.stringify(err), + message: getContext().resourceManager.getStringByNameSync("Forwarded_failure") + JSON.stringify(err), duration: 2500 }) } @@ -516,7 +516,7 @@ struct Smtp { } ListItem() { - Text('Reply e-mail') + Text($r('app.string.Reply_to_Email')) .fontColor('#333333') .fontSize(20) .fontWeight(800) @@ -525,17 +525,17 @@ struct Smtp { ListItem() { Column({ space: 12 }) { - Text('Index of emails that need to be replied to') + Text($r('app.string.Index_of_email_to_reply_to')) .fontSize(16) .margin({ top: 5 }) - TextInput({ text: this.replyMsgIndex + "", placeholder: 'Index of emails that need to be replied to' }) + TextInput({ text: this.replyMsgIndex + "", placeholder: $r('app.string.Index_of_email_to_reply_to')}) .height(60) .fontSize(18) .type(InputType.Number) .onChange((value: string) => { this.replyMsgIndex = Number.parseInt(value) }) - Button('Reply e-mail', { type: ButtonType.Normal }) + Button($r('app.string.Reply_to_Email'), { type: ButtonType.Normal }) .fontSize(18) .fontColor('#000') .height(60) @@ -599,7 +599,7 @@ struct Smtp { try { let attachBody = mime.getAttachment(i) //接收附件数据的文件 - let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-annex-" + i + ".txt"; + let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-"+getContext().resourceManager.getStringByNameSync("annex")+"-" + i + ".txt"; let attachmentFile = fs.openSync( attachmentFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.APPEND @@ -640,7 +640,7 @@ struct Smtp { try { let attachBody = mime.getInlineAttachment(i) //接收附件数据的文件 - let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-Inline attachments-" + i + ".txt"; + let attachmentFilePath = this.filesPath + "/" + this.frowardMsgIndex + "-"+getContext().resourceManager.getStringByNameSync("Inline_attachments")+"-" + i + ".txt"; let attachmentFile = fs.openSync( attachmentFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.APPEND @@ -692,13 +692,13 @@ struct Smtp { mimeMessage.setRecipients(RecipientType.BCC, this.Bc) mimeMessage.setSubject("reply:" + message.getSubject()) - let text = "regression testing\r\n\r\n\r\n" - + "------------------ original message ------------------\r\n" - + "Sender: " + message.getFrom() + "\r\n" - + "Sending time: " + message.getSentDate() + "\r\n" + let text = getContext().resourceManager.getStringByNameSync("Reply_testing")+ "\r\n\r\n\r\n" + + "------------------ "+getContext().resourceManager.getStringByNameSync("original_email")+" ------------------\r\n" + + getContext().resourceManager.getStringByNameSync("Sender") + message.getFrom() + "\r\n" + + getContext().resourceManager.getStringByNameSync("Sending_time") + message.getSentDate() + "\r\n" let to = message.getRecipients(RecipientType.TO) if (!!to) { - text += "recipient: " + text += getContext().resourceManager.getStringByNameSync("Recipient") for (let i = 0; i < to.length; i++) { if (i != to.length - 1) { text += to[i] + "," @@ -708,10 +708,10 @@ struct Smtp { } } - text += "theme: " + message.getSubject() + "\r\n" + text += getContext().resourceManager.getStringByNameSync("Subject") + message.getSubject() + "\r\n" let cc = message.getRecipients(RecipientType.CC) if (!!cc) { - text += "make a copy for: " + text += getContext().resourceManager.getStringByNameSync("CC") for (let i = 0; i < cc.length; i++) { if (i != cc.length - 1) { text += cc[i] + "," @@ -721,7 +721,7 @@ struct Smtp { } } if (!!message.getRecipients(RecipientType.BCC)) { - text += "bcc: " + message.getRecipients(RecipientType.BCC) + "\r\n" + text += getContext().resourceManager.getStringByNameSync("bcc") + message.getRecipients(RecipientType.BCC) + "\r\n" } text += "\r\n\r\n" if (!!textBody) { @@ -744,12 +744,12 @@ struct Smtp { if (!err) { MailLogger.info('ohos_mail-- send message success'); prompt.showToast({ - message: "Reply successful!", + message: getContext().resourceManager.getStringByNameSync("Replied_successfully"), duration: 2500 }) } else { prompt.showToast({ - message: "Reply failed:" + JSON.stringify(err), + message: getContext().resourceManager.getStringByNameSync("Replied_failure") + JSON.stringify(err), duration: 2500 }) } @@ -819,8 +819,8 @@ async function asyncTask(host: string, port: number, sendFrom: string, to: strin let cacheContent = GlobalContext.getContext().getValue('cacheContent'); let ret = await Promise.all([ new Promise((resolve, reject) => { - let subject = "This is subject" - let text = "This is text" + let subject = getContext().resourceManager.getStringByNameSync("This_is_subject") + let text = getContext().resourceManager.getStringByNameSync("This_is_text") let properties = new Properties() properties.setFrom(sendFrom) properties.setHost(host) diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 4c51c0da06c317dde39718eaa7a88d7d54946570..cbe992937c76e55ec1cb5968858be8cf4def9fc8 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -11,6 +11,370 @@ { "name": "EntryAbility_label", "value": "ohos_mail" + }, + { + "name": "smtp_protocol", + "value": "smtp protocol" + }, + { + "name": "pop3_protocol", + "value": "pop3 protocol" + }, + { + "name": "imap_protocol", + "value": "imap protocol" + }, + { + "name": "Parse_Email", + "value": "Parse Email" + }, + { + "name": "mimeType", + "value": "mimeType" + }, + { + "name": "Please_select_an_email_address", + "value": "Please select an email address" + }, + { + "name": "Enable_SSL", + "value": "Enable SSL" + }, + { + "name": "Receiving_server", + "value": "Receiving server" + }, + { + "name": "Please_enter_the_Receiving_server", + "value": "Please enter the Receiving server" + }, + { + "name": "Receiving_server_port", + "value": "Receiving server port" + }, + { + "name": "Please_enter_the_Receiving_server_port", + "value": "Please enter the Receiving server port" + }, + { + "name": "Receive_Email", + "value": "Receive Email" + }, + { + "name": "Please_enter_the_Receive_Email", + "value": "Please enter the Receive Email" + }, + { + "name": "Recipient_email_authorization_code", + "value": "Recipient email authorization code" + }, + { + "name": "Please_enter_the_Recipient_email_authorization_code", + "value": "Please enter the Recipient email authorization code" + }, + { + "name": "Index_of_email_to_read", + "value": "Index of email to read" + }, + { + "name": "Sender", + "value": "Sender: " + }, + { + "name": "Recipient", + "value": "Recipient: " + }, + { + "name": "Subject", + "value": "Subject: " + }, + { + "name": "Date", + "value": "Date: " + }, + { + "name": "main_body", + "value": "main body " + }, + { + "name": "annex", + "value": "annex " + }, + { + "name": "Data", + "value": "Data: " + }, + { + "name": "CharSet", + "value": "CharSet: " + }, + { + "name": "MimeType", + "value": "MimeType: " + }, + { + "name": "TransferEncoding", + "value": "TransferEncoding: " + }, + { + "name": "Html", + "value": "Html " + }, + { + "name": "Headers", + "value": "Headers " + }, + { + "name": "Calendar", + "value": "Calendar " + }, + { + "name": "FileName", + "value": "File Name: " + }, + { + "name": "Receive_Mail_taskpool", + "value": "Receive Mail(taskpool)" + }, + { + "name": "Email_content", + "value": "Email content" + }, + { + "name": "update", + "value": "update" + }, + { + "name": "Update_email", + "value": "Update email(Get the last 10 emails)" + }, + { + "name": "Delete_mail", + "value": "Delete mail" + }, + { + "name": "The_number_of_the_mail_to_delete", + "value": "The number of the message to delete" + }, + { + "name": "Delete_successfully", + "value": "Delete successfully" + }, + { + "name": "Delete_failed", + "value": "Delete failed" + }, + { + "name": "This_email_does_not_exist", + "value": "This email does not exist" + }, + { + "name": "move_Mail", + "value": "move Mail" + }, + { + "name": "To_move_the_email_number", + "value": "To move the email number" + }, + { + "name": "Move_successful", + "value": "Move successful" + }, + { + "name": "Test_email_sending", + "value": "Test email sending" + }, + { + "name": "This_is_a_test_email", + "value": "This is a test email" + }, + { + "name": "Parse_and_Construct_Email", + "value": "Parse and Construct Email" + }, + { + "name": "parsing_failed", + "value": "parsing failed:" + }, + { + "name": "filename_sample_eml", + "value": "File name:sample.eml" + }, + { + "name": "parsing_results", + "value": "Parsing result:" + }, + { + "name": "Email_construction", + "value": "Construct" + }, + { + "name": "construction_resules", + "value": "Construction result:" + }, + { + "name": "Sending_server", + "value": "Sending server" + }, + { + "name": "Please_enter_the_Sending_server", + "value": "Please enter the Sending server" + }, + { + "name": "Sending_server_port", + "value": "Sending server port" + }, + { + "name": "Please_enter_the_Sending_server_port", + "value": "Please enter the Sending server port" + }, + { + "name": "Send_Email", + "value": "Send Email" + }, + { + "name": "Sender_email_authorization_code", + "value": "Sender email authorization code" + }, + { + "name": "Please_enter_the_Sender_email_authorization_code", + "value": "Please enter the Sender email authorization code" + }, + { + "name": "Please_enter_the_recipient_email_address_multiple_email_addresses_separated", + "value": "Please enter the recipient email address, multiple email addresses separated" + }, + { + "name": "CC_email", + "value": "CC email" + }, + { + "name": "Please_ente_the_cc_recipients_email_address", + "value": "Please enter the cc recipient's email address" + }, + { + "name": "BCC_email", + "value": "BCC email" + }, + { + "name": "Please_enter_the_BCC_email", + "value": "Please enter the BCC email address" + }, + { + "name": "Please_enter_the_sending_email_address", + "value": "Please enter the sending email address" + }, + { + "name": "Please_enter_the_Subject", + "value": "Please enter the Subject" + }, + { + "name": "Body", + "value": "Body" + }, + { + "name": "Please_enter_the_Body", + "value": "Please enter the Body" + }, + { + "name": "Sent_successfully", + "value": "Sent successfully!" + }, + { + "name": "Send_failure", + "value": "Send failure: " + }, + { + "name": "Forward", + "value": "Forward" + }, + { + "name": "Forwarding_test", + "value": "Forwarding test" + }, + { + "name": "Inline_attachments", + "value": "Inline attachments" + }, + { + "name": "original_email", + "value": "original email" + }, + { + "name": "Sending_time", + "value": "Sending time" + }, + { + "name": "CC", + "value": "CC: " + }, + { + "name": "Forwarded_successfully", + "value": "Forwarded successfully." + }, + { + "name": "Forwarded_failure", + "value": "Forwarded failure" + }, + { + "name": "Reply_to_Email", + "value": "Reply to Email" + }, + { + "name": "Index_of_email_to_forward", + "value": "Index of email to forward" + }, + { + "name": "Index_of_email_to_reply_to", + "value": "Index of email to reply to" + }, + { + "name": "Reply_testing", + "value": "Reply testing" + }, + { + "name": "bcc", + "value": "bcc: " + }, + { + "name": "Replied_successfully", + "value": "Replied successfully." + }, + { + "name": "Replied_failure", + "value": "Replied failure." + }, + { + "name": "This_is_subject", + "value": "This is subject" + }, + { + "name": "This_is_text", + "value": "This is text" + }, + { + "name": "Recipient_email", + "value": "Recipient email" + }, + { + "name": "Please_enter_the_Recipient_email", + "value": "Please enter the Recipient email" + }, + { + "name": "Test_MIME_Type", + "value": "Test MIME Type" + }, + { + "name": "test_otherfile_mimetype", + "value": "test otherfile mimetype" + }, + { + "name": "Resolving", + "value": "Resolving..." + }, + { + "name": "Resolving_result", + "value": "Resolving result : " } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 4c51c0da06c317dde39718eaa7a88d7d54946570..5b3c104b3556c8ba935e120f529d80e112be5b83 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -11,6 +11,370 @@ { "name": "EntryAbility_label", "value": "ohos_mail" + }, + { + "name": "smtp_protocol", + "value": "smtp protocol" + }, + { + "name": "pop3_protocol", + "value": "pop3 protocol" + }, + { + "name": "imap_protocol", + "value": "imap protocol" + }, + { + "name": "Parse_Email", + "value": "Parse Email" + }, + { + "name": "mimeType", + "value": "mimeType" + }, + { + "name": "Please_select_an_email_address", + "value": "Please select an email address" + }, + { + "name": "Enable_SSL", + "value": "Enable SSL" + }, + { + "name": "Receiving_server", + "value": "Receiving server" + }, + { + "name": "Please_enter_the_Receiving_server", + "value": "Please enter the Receiving server" + }, + { + "name": "Receiving_server_port", + "value": "Receiving server port" + }, + { + "name": "Please_enter_the_Receiving_server_port", + "value": "Please enter the Receiving server port" + }, + { + "name": "Receive_Email", + "value": "Receive Email" + }, + { + "name": "Please_enter_the_Receive_Email", + "value": "Please enter the Receive Email" + }, + { + "name": "Recipient_email_authorization_code", + "value": "Recipient email authorization code" + }, + { + "name": "Please_enter_the_Recipient_email_authorization_code", + "value": "Please enter the Recipient email authorization code" + }, + { + "name": "Index_of_email_to_read", + "value": "Index of email to read" + }, + { + "name": "Sender", + "value": "Sender: " + }, + { + "name": "Recipient", + "value": "Recipient: " + }, + { + "name": "Subject", + "value": "Subject: " + }, + { + "name": "Date", + "value": "Date: " + }, + { + "name": "main_body", + "value": "main body " + }, + { + "name": "annex", + "value": "annex " + }, + { + "name": "Data", + "value": "Data: " + }, + { + "name": "CharSet", + "value": "CharSet: " + }, + { + "name": "MimeType", + "value": "MimeType: " + }, + { + "name": "TransferEncoding", + "value": "TransferEncoding: " + }, + { + "name": "Html", + "value": "Html " + }, + { + "name": "Headers", + "value": "Headers " + }, + { + "name": "Calendar", + "value": "Calendar " + }, + { + "name": "FileName", + "value": "FileName: " + }, + { + "name": "Receive_Mail_taskpool", + "value": "Receive Mail(taskpool)" + }, + { + "name": "Email_content", + "value": "Email content" + }, + { + "name": "update", + "value": "update" + }, + { + "name": "Update_email", + "value": "Update email(Get the last 10 emails)" + }, + { + "name": "Delete_mail", + "value": "Delete mail" + }, + { + "name": "The_number_of_the_mail_to_delete", + "value": "The number of the message to delete" + }, + { + "name": "Delete_successfully", + "value": "Delete successfully" + }, + { + "name": "Delete_failed", + "value": "Delete failed" + }, + { + "name": "This_email_does_not_exist", + "value": "This email does not exist" + }, + { + "name": "move_Mail", + "value": "move Mail" + }, + { + "name": "To_move_the_email_number", + "value": "To move the email number" + }, + { + "name": "Move_successful", + "value": "Move successful" + }, + { + "name": "Test_email_sending", + "value": "Test email sending" + }, + { + "name": "This_is_a_test_email", + "value": "This is a test email" + }, + { + "name": "Parse_and_Construct_Email", + "value": "Parse and Construct Email" + }, + { + "name": "parsing_failed", + "value": "parsing failed:" + }, + { + "name": "filename_sample_eml", + "value": "File name:sample.eml" + }, + { + "name": "parsing_results", + "value": "Parsing result:" + }, + { + "name": "Email_construction", + "value": "Construct" + }, + { + "name": "construction_resules", + "value": "Construction result:" + }, + { + "name": "Sending_server", + "value": "Sending server" + }, + { + "name": "Please_enter_the_Sending_server", + "value": "Please enter the Sending server" + }, + { + "name": "Sending_server_port", + "value": "Sending server port" + }, + { + "name": "Please_enter_the_Sending_server_port", + "value": "Please enter the Sending server port" + }, + { + "name": "Send_Email", + "value": "Send Email" + }, + { + "name": "Sender_email_authorization_code", + "value": "Sender email authorization code" + }, + { + "name": "Please_enter_the_Sender_email_authorization_code", + "value": "Please enter the Sender email authorization code" + }, + { + "name": "Please_enter_the_recipient_email_address_multiple_email_addresses_separated", + "value": "Please enter the recipient email address, multiple email addresses separated" + }, + { + "name": "CC_email", + "value": "CC email" + }, + { + "name": "Please_ente_the_cc_recipients_email_address", + "value": "Please enter the cc recipient's email address" + }, + { + "name": "BCC_email", + "value": "BCC email" + }, + { + "name": "Please_enter_the_BCC_email", + "value": "Please enter the BCC email address" + }, + { + "name": "Please_enter_the_sending_email_address", + "value": "Please enter the sending email address" + }, + { + "name": "Please_enter_the_Subject", + "value": "Please enter the Subject" + }, + { + "name": "Body", + "value": "Body" + }, + { + "name": "Please_enter_the_Body", + "value": "Please enter the Body" + }, + { + "name": "Sent_successfully", + "value": "Sent successfully!" + }, + { + "name": "Send_failure", + "value": "Send failure: " + }, + { + "name": "Forward", + "value": "Forward" + }, + { + "name": "Forwarding_test", + "value": "Forwarding test" + }, + { + "name": "Inline_attachments", + "value": "Inline attachments" + }, + { + "name": "original_email", + "value": "original email" + }, + { + "name": "Sending_time", + "value": "Sending time" + }, + { + "name": "CC", + "value": "CC: " + }, + { + "name": "Forwarded_successfully", + "value": "Forwarded successfully." + }, + { + "name": "Forwarded_failure", + "value": "Forwarded failure" + }, + { + "name": "Reply_to_Email", + "value": "Reply to Email" + }, + { + "name": "Index_of_email_to_forward", + "value": "Index of email to forward" + }, + { + "name": "Index_of_email_to_reply_to", + "value": "Index of email to reply to" + }, + { + "name": "Reply_testing", + "value": "Reply testing" + }, + { + "name": "bcc", + "value": "bcc: " + }, + { + "name": "Replied_successfully", + "value": "Replied successfully." + }, + { + "name": "Replied_failure", + "value": "Replied failure." + }, + { + "name": "This_is_subject", + "value": "This is subject" + }, + { + "name": "This_is_text", + "value": "This is text" + }, + { + "name": "Recipient_email", + "value": "Recipient email" + }, + { + "name": "Please_enter_the_Recipient_email", + "value": "Please enter the Recipient email" + }, + { + "name": "Test_MIME_Type", + "value": "Test MIME Type" + }, + { + "name": "test_otherfile_mimetype", + "value": "test otherfile mimetype" + }, + { + "name": "Resolving", + "value": "Resolving..." + }, + { + "name": "Resolving_result", + "value": "Resolving result : " } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 5388b9b765a18eaf7d1c8e2e004a4ca8117635a0..93a94fc9f845066416e539db7ef8a37153b592c9 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,370 @@ { "name": "EntryAbility_label", "value": "ohos_mail" + }, + { + "name": "smtp_protocol", + "value": "smtp 协议" + }, + { + "name": "pop3_protocol", + "value": "pop3 协议" + }, + { + "name": "imap_protocol", + "value": "imap 协议" + }, + { + "name": "Parse_Email", + "value": "邮件解析" + }, + { + "name": "mimeType", + "value": "mimeType" + }, + { + "name": "Please_select_an_email_address", + "value": "请选择邮箱" + }, + { + "name": "Enable_SSL", + "value": "开启SSL" + }, + { + "name": "Receiving_server", + "value": "接件服务器" + }, + { + "name": "Please_enter_the_Receiving_server", + "value": "请输入接件服务器" + }, + { + "name": "Receiving_server_port", + "value": "接件服务器端口" + }, + { + "name": "Please_enter_the_Receiving_server_port", + "value": "请输入接件服务器端口" + }, + { + "name": "Receive_Email", + "value": "接件邮箱" + }, + { + "name": "Please_enter_the_Receive_Email", + "value": "请输入接件邮箱" + }, + { + "name": "Recipient_email_authorization_code", + "value": "接件邮箱授权码" + }, + { + "name": "Please_enter_the_Recipient_email_authorization_code", + "value": "请输入接件邮箱授权码" + }, + { + "name": "Index_of_email_to_read", + "value": "需要读取邮件的索引" + }, + { + "name": "Sender", + "value": "发送人: " + }, + { + "name": "Recipient", + "value": "接收人: " + }, + { + "name": "Subject", + "value": "主题: " + }, + { + "name": "Date", + "value": "日期: " + }, + { + "name": "main_body", + "value": "正文 " + }, + { + "name": "annex", + "value": "附件 " + }, + { + "name": "Data", + "value": "数据: " + }, + { + "name": "CharSet", + "value": "字符集: " + }, + { + "name": "MimeType", + "value": "MimeType: " + }, + { + "name": "TransferEncoding", + "value": "编码: " + }, + { + "name": "Html", + "value": "Html " + }, + { + "name": "Headers", + "value": "Headers " + }, + { + "name": "Calendar", + "value": "日历 " + }, + { + "name": "FileName", + "value": "文件名: " + }, + { + "name": "Receive_Mail_taskpool", + "value": "接收邮件(taskpool)" + }, + { + "name": "Email_content", + "value": "邮件内容" + }, + { + "name": "update", + "value": "更新" + }, + { + "name": "Update_email", + "value": "更新邮箱(获取最近10封邮件)" + }, + { + "name": "Delete_mail", + "value": "删除邮件" + }, + { + "name": "The_number_of_the_mail_to_delete", + "value": "要删除邮件的编号" + }, + { + "name": "Delete_successfully", + "value": "删除成功" + }, + { + "name": "Delete_failed", + "value": "删除失败" + }, + { + "name": "This_email_does_not_exist", + "value": "不存在此邮件" + }, + { + "name": "move_Mail", + "value": "移动邮件" + }, + { + "name": "To_move_the_email_number", + "value": "要移动邮件的编号" + }, + { + "name": "Move_successful", + "value": "移动成功" + }, + { + "name": "Test_email_sending", + "value": "测试邮件发送" + }, + { + "name": "This_is_a_test_email", + "value": "这是一个测试邮件" + }, + { + "name": "Parse_and_Construct_Email", + "value": "邮件解析、构建" + }, + { + "name": "parsing_failed", + "value": "解析失败:" + }, + { + "name": "filename_sample_eml", + "value": "文件名:sample.eml" + }, + { + "name": "parsing_results", + "value": "解析结果 : " + }, + { + "name": "Email_construction", + "value": "构建" + }, + { + "name": "construction_resules", + "value": "构建结果 : " + }, + { + "name": "Sending_server", + "value": "发件服务器" + }, + { + "name": "Please_enter_the_Sending_server", + "value": "请输入发件服务器" + }, + { + "name": "Sending_server_port", + "value": "发件服务器端口" + }, + { + "name": "Please_enter_the_Sending_server_port", + "value": "请输入发件服务器端口" + }, + { + "name": "Send_Email", + "value": "发送邮件" + }, + { + "name": "Sender_email_authorization_code", + "value": "发件邮箱授权码" + }, + { + "name": "Please_enter_the_Sender_email_authorization_code", + "value": "请输入发件邮箱授权码" + }, + { + "name": "Please_enter_the_recipient_email_address_multiple_email_addresses_separated", + "value": "请输入收件邮箱,多个邮箱 , 隔开" + }, + { + "name": "CC_email", + "value": "抄送邮箱" + }, + { + "name": "Please_ente_the_cc_recipients_email_address", + "value": "请输入抄送邮箱地址" + }, + { + "name": "BCC_email", + "value": "密送邮箱" + }, + { + "name": "Please_enter_the_BCC_email", + "value": "请输入密送邮箱地址" + }, + { + "name": "Please_enter_the_sending_email_address", + "value": "请输入发送邮箱地址" + }, + { + "name": "Please_enter_the_Subject", + "value": "请输入主题" + }, + { + "name": "Body", + "value": "邮件文本内容" + }, + { + "name": "Please_enter_the_Body", + "value": "请输入邮件文本内容" + }, + { + "name": "Sent_successfully", + "value": "发送成功!" + }, + { + "name": "Send_failure", + "value": "发送失败: " + }, + { + "name": "Forward", + "value": "转发" + }, + { + "name": "Forwarding_test", + "value": "转发测试" + }, + { + "name": "Inline_attachments", + "value": "内联附件" + }, + { + "name": "original_email", + "value": "原始邮件" + }, + { + "name": "Sending_time", + "value": "发送时间" + }, + { + "name": "CC", + "value": "抄送: " + }, + { + "name": "Forwarded_successfully", + "value": "转发成功." + }, + { + "name": "Forwarded_failure", + "value": "转发失败" + }, + { + "name": "Reply_to_Email", + "value": "回复邮件" + }, + { + "name": "Index_of_email_to_forward", + "value": "需要转发邮件的索引" + }, + { + "name": "Index_of_email_to_reply_to", + "value": "需要回复邮件的索引" + }, + { + "name": "Reply_testing", + "value": "回复测试" + }, + { + "name": "bcc", + "value": "密送: " + }, + { + "name": "Replied_successfully", + "value": "回复成功!" + }, + { + "name": "Replied_failure", + "value": "回复失败" + }, + { + "name": "This_is_subject", + "value": "这是一个主题" + }, + { + "name": "This_is_text", + "value": "这是一个文本" + }, + { + "name": "Recipient_email", + "value": "收件邮箱" + }, + { + "name": "Please_enter_the_Recipient_email", + "value": "请输入收件邮箱" + }, + { + "name": "Test_MIME_Type", + "value": "测试 MIME Type" + }, + { + "name": "test_otherfile_mimetype", + "value": "测试其他 mimetype" + }, + { + "name": "Resolving", + "value": "正在解析..." + }, + { + "name": "Resolving_result", + "value": "构建结果 : " } ] } \ No newline at end of file diff --git a/image/sample.gif b/image/sample.gif deleted file mode 100644 index 1e247f44f9807528e4b7157d350a6dd81774c876..0000000000000000000000000000000000000000 Binary files a/image/sample.gif and /dev/null differ diff --git a/image/sample_EN.gif b/image/sample_EN.gif deleted file mode 100644 index 6d2b206ed4a024e9405b82302cbc05e559b4d765..0000000000000000000000000000000000000000 Binary files a/image/sample_EN.gif and /dev/null differ