diff --git a/FTPClient/CHANGELOG.md b/FTPClient/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..3a14a3ab46e460765b589b68b6ad617021ebb7ba --- /dev/null +++ b/FTPClient/CHANGELOG.md @@ -0,0 +1,5 @@ +## 1.0.0 +- 支持FTP/FTPS协议 + + + diff --git a/FTPClient/LICENSE.txt b/FTPClient/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..804e800dc0e37058fc2db08599950d5c6e809072 --- /dev/null +++ b/FTPClient/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2019 Patrick Juchli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/FTPClient/NOTICE b/FTPClient/NOTICE new file mode 100644 index 0000000000000000000000000000000000000000..546e4d4be4479edd9f87b505f2f9d98dce04d3d1 --- /dev/null +++ b/FTPClient/NOTICE @@ -0,0 +1,34 @@ +OPEN SOURCE SOFTWARE NOTICE + +Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders. + +Warranty Disclaimer +THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + +Copyright Notice and License Texts + +---------------------------------------------------------------------- +Software: basic-ftp + +Copyright notice: +[MIT](https://github.com/patrickjuchli/basic-ftp/blob/master/LICENSE.txt) + +Copyright 2019 Square, Inc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/FTPClient/README.OpenSource b/FTPClient/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..41d4789f186062af88904f64aac9d64a9bc11fa3 --- /dev/null +++ b/FTPClient/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": " basic-ftp", + "License": " MIT ", + "License File": " LICENSE.txt ", + "Version Number": " v5.0.3 ", + "Owner": "xiafeng@huawei.com", + "Upstream URL": " https://github.com/patrickjuchli/basic-ftp ", + "Description": " This is an FTP client library for Node.js. It supports FTPS over TLS, Passive Mode over IPv6, has a Promise-based API, and offers methods to operate on whole directories. " + } +] diff --git a/FTPClient/README.md b/FTPClient/README.md new file mode 100644 index 0000000000000000000000000000000000000000..770c522b9168184adb74839051ffa059d14679a6 --- /dev/null +++ b/FTPClient/README.md @@ -0,0 +1,588 @@ + + +## FTPClient + +## 简介 + +FTPClient是一个提供FTP/FTPS传输协议的客户端。 + +## 下载安装 + +```javascript +ohpm install @ohos/FTPClient +``` + +OpenHarmony ohpm +环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) + + + +## 使用说明 + +``` +import { AccessOptions, FileInfo, FileType, FTPResponse, UnixPermissions } from '@ohos/basic-ftp' +import buffer from '@ohos.buffer' +import socket from '@ohos.net.socket'; +import NoTlsUtil from '../utils/FtpApiUtil' +``` + + +### 登录FTP服务器 + + ```javascript + + let option = { + ALPNProtocols: ["spdy/1", "http/1.1"], + address: { + address: '1.15.87.xx', + port: 21, + family: 1 + }, + secureOptions: { + key: '', + cert: '', + ca: [''], + password: 'xxxxx', + protocols: [socket.Protocol.TLSv12, socket.Protocol.TLSv13], + useRemoteCipherPrefer: true, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256" + } + } + + let loginInfo = { + host: '1.15.87.x', + user: 'xxxxxxxx', + password: 'xxxxxx', + secure: 'implicit', + secureOptions: option + } + + ftpUtil.doLogin(loginInfo, { + onLoginStart(info) { + }, + onLoginSuccess(result) { + }, + onLoginErr(err: Error) { + } + }) + + ``` + +### 获取文件列表 + +```javascript +if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return; + } + let startTime1 = new Date().getTime(); + ftpUtil.getCurrentDirectory({ + currentDirectoryErr(err: Error) { + }, + currentDirectoryStart(info) { + }, + currentDirectorySuccess(msg) { + remoteRoot = msg + let listName = ''; + if (remoteRoot == '' || remoteRoot == '\\' || remoteRoot == '/') { + listName = '' + } else { + listName = msg + } + ftpUtil.getList(listName, { + getListErr(err: Error) { + }, + getListStart(info) { + }, + getListSuccess(result: FileInfo[]) { + + } + }) + + } + }) +} +``` + +### 上传单个文件 + + ```javascript +if (ftpUtil) { + if (!ftpUtil.getLogin()) { + operationType = '' + return + } + if (!localUploadFilePath || localUploadFilePath.length < 1) { + operationType = '' + return + } + if (!remoteRoot || remoteRoot.length < 1) { + operationType = '' + return + } + inputValue = "clientToServer.txt" + if (!inputValue || inputValue.length < 1) { + operationType = '' + return + } + ftpUtil.uploadSingleFile(localUploadFilePath, inputValue, { + uploadErr(err: Error) { + }, + uploadStart(info) { + }, + uploadSuccess(msg: FTPResponse) { + + }, + uploadProgress(currentSize: number, totalSize: number) { + } + }) +} + ``` + +### 上传文件夹 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + operationType = '' + return + } + if (!localUploadFileDir || localUploadFileDir.length < 1) { + operationType = '' + return + } + if (!remoteRoot || remoteRoot.length < 1) { + operationType = '' + return + } + inputValue = "client" + if (!inputValue || inputValue.length < 1) { + operationType = '' + return + } + let regex = new RegExp(`^(?!_)(?!.*?_$)[a-zA-Z0-9_u4e00-u9fa5]+$`); //正则表达式 + if (!regex.test(inputValue)) { + operationType = '' + return + } + ftpUtil.uploadDir(localUploadFileDir, inputValue, { + uploadDirErr(err: Error) { + }, + uploadDirStart(info) { + }, + uploadDirSuccess(msg) { + }, + uploadDirProgress(currentSize: number, totalSize: number) { + } + }) +} + ``` + +### 下载单个文件 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectFilePath = "clientToServer.txt"; + if (!selectFilePath || selectFilePath.length < 1) { + return + } + ftpUtil.downloadSingleFile(localPath, selectFilePath, { + downloadErr(err: Error) { + expect(0).assertEqual(1) + done() + }, + downloadStart(info) { + }, + downloadSuccess(msg: FTPResponse) { + }, + downloadProgress(currentSize: number, totalSize: number) { + } + }) +} + ``` + +### 下载文件夹 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectDirPath = "client" + if (!selectDirPath || selectDirPath.length < 1) { + return + } + ftpUtil.downloadDir(localDir, selectDirPath, { + downloadDirErr(err: Error) { + }, + downloadDirStart(info) { + }, + downloadDirSuccess(msg) { + + }, + downloadDirProgress(currentSize: number, totalSize: number) { + } + }) +} + ``` + +### 获取文件大小 + +```javascript +if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectFilePath = "clientToServer.txt"; + if (!selectFilePath || selectFilePath.length < 1) { + return + } + ftpUtil.getFileSize(selectFilePath, { + getSizeErr(err: Error) { + }, + getSizeStart(info) { + }, + getSizeSuccess(result: number) { + } + }) +} + ``` +### 获取服务器能力 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + ftpUtil.getServerFeatures({ + featuresErr(err: Error) { + }, + featuresStart(info) { + }, + featuresSuccess(msg: Map) { + } + }) +} + ``` +### 获取最后修改时间 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectFilePath = "clientToServer.txt"; + + if (!selectFilePath || selectFilePath.length < 1) { + return + } + ftpUtil.getLastModify(selectFilePath, { + lastModifyErr(err: Error) { + }, + lastModifyStart(info) { + }, + lastModifySuccess(msg: Date) { + } + }) + } + ``` +### 重命名文件 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + operationType = '' + return + } + if (!remoteRoot || remoteRoot.length < 1) { + operationType = '' + return + } + + inputValue = "clientToServerNew.txt" + if (!inputValue || inputValue.length < 1) { + operationType = '' + return + } + selectFilePath = "clientToServer.txt"; + + if (!selectFilePath || selectFilePath.length < 1) { + return + } + ftpUtil.renameFile(inputValue, selectFilePath, { + renameFileErr(err: Error) { + }, + renameFileStart(info) { + operationType = '' + }, + renameFileSuccess(result: FTPResponse) { + } + }) + } + ``` +### 切换目录 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + if (!remoteRoot || remoteRoot.length < 1) { + return + } + ftpUtil.cdToParentDirectory({ + cdToParentDirectoryErr(err: Error) { + + }, + cdToParentDirectoryStart(info) { + }, + cdToParentDirectorySuccess(res: FTPResponse) { + + } + }) + } + ``` +### 确认远端路径 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + operationType = '' + return + } + if (!remoteRoot || remoteRoot.length < 1) { + operationType = '' + return + } + inputValue = "client" + if (!inputValue || inputValue.length < 1) { + operationType = '' + return + } + let regex = new RegExp(`^(?!_)(?!.*?_$)[a-zA-Z0-9_u4e00-u9fa5]+$`); //正则表达式 + if (!regex.test(inputValue)) { + operationType = '' + return + } + ftpUtil.ensureRemotePath(inputValue, { + ensureRemotePathErr(err: Error) { + + }, + ensureRemotePathStart(info) { + }, + ensureRemotePathSuccess(result) { + + } + }) + } + ``` +### 删除空目录 + +```javascript +if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectDirPath = "/testempty" + if (!selectDirPath || selectDirPath.length < 1) { + return + } + let startTime1 = new Date().getTime(); + ftpUtil.deleteEmptyDirectory(selectDirPath, { + deleteEmptyDirectoryErr(err: Error) { + + }, + deleteEmptyDirectoryStart(info) { + }, + deleteEmptyDirectorySuccess(result: FTPResponse) { + + } + }) + } + ``` +### 删除单个文件 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectFilePath = "/clientToServerNew.txt"; + + if (!selectFilePath || selectFilePath.length < 1) { + return + } + ftpUtil.deleteFile(selectFilePath, { + deleteFileErr(err: Error) { + }, + deleteFileStart(info) { + }, + deleteFileSuccess(msg: FTPResponse) { + } + }) +} + ``` + +### 删除所有文件 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + selectDirPath="/deleteAll" + if (!selectDirPath || selectDirPath.length < 1) { + return + } + let startTime1 = new Date().getTime(); + ftpUtil.deleteAll(selectDirPath, { + deleteAllErr(err: Error) { + + }, + deleteAllStart(info) { + }, + deleteAllSuccess(result) { + + } + }) + } + ``` + +### 删除当前目录下的所有文件 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + remoteChildPath="/deleteSelfBuf" + let startTime1 = new Date().getTime(); + ftpUtil.setWorkingDirectory(remoteChildPath, { + setWorkingDirectoryErr(err: Error) { + + }, + setWorkingDirectoryStart(info) { + }, + setWorkingDirectorySuccess(result: FTPResponse) { + ftpUtil.deleteAllButSelf({ + deleteAllButSelfErr(err: Error) { + + }, + deleteAllButSelfStart(info) { + }, + deleteAllButSelfSuccess(result) { + + } + }) + } + }) + } + ``` + +### 设置工作目录 + +```javascript + if (ftpUtil) { + if (!ftpUtil.getLogin()) { + return + } + remoteRoot="/" + if (!remoteRoot || remoteRoot.length < 1) { + return + } + remoteChildPath="/client" + if (!remoteChildPath || remoteChildPath.length < 1) { + return + } + ftpUtil.setWorkingDirectory(remoteChildPath, { + setWorkingDirectoryErr(err: Error) { + + }, + setWorkingDirectoryStart(info) { + }, + setWorkingDirectorySuccess(result: FTPResponse) { + + } + }) + } + ``` + +## 接口说明 + +### client: Client = new Client(context, timeOut) + +| 接口名 | 参数 | 返回值 | 说明 | +| ----------------- | ------------------------------ | ------------------ | ---------------------------------------- | +| access | AccessOptions | FTPResponse | 登录FTP服务器 +| list | string | FileInfo | 获取文件列表 | +| size | string | number | 获取文件大小 | +| uploadFrom | string, string | FTPResponse | 上传文件 | +| downloadTo | string, string | FTPResponse | 下载文件 | +| features | 无 | Map | 获取服务器能力 | +| cd | string | FTPResponse | 设置工作目录 | +| cdup | 无 | FTPResponse | 切换工作目录 | +| remove | string | FTPResponse | 删除文件 | +| lastMod | string | Date | 获取最后修改的时间 | +| pwd | 无 | string | 获取当前目录 | +| ensureDir | string | void | 确认远程是否存在目录 | +| removeEmptyDir | string | FTPResponse | 删除空目录 | +| removeDir | string | void | 删除所有目录和文件 | +| clearWorkingDir | 无 | void | 清理当前目录 | +| rename | string, string | FTPResponse | 重命名文件 | +| uploadFromDir | string, string | void | 上传目录 | +| downloadToDir | string, string | void | 下载目录 | + + +## 约束与限制 +在下述版本验证通过: +DevEco Studio版本: 4.0 Release(4.0.3.413), SDK: (4.0.10.3) + +## 目录结构 + +```javascript +|---- FTPClient +| |---- entry # 示例代码文件夹 +| |---- BasicFtp # FTPClient 库文件夹 +| |---- README.MD # 安装使用方法 +``` + +## 贡献代码 + +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/pulls) 。 + +## 开源协议 + +本项目基于 [MIT](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/blob/master/FTPClient/LICENSE.txt) ,请自由地享受和参与开源。 \ No newline at end of file diff --git a/FTPClient/entry/src/main/ets/entryability/EntryAbility.ts b/FTPClient/entry/src/main/ets/entryability/EntryAbility.ts index 4ded4937ff066ef8569b26dc52ed1f9222996b09..26ea5ee33b46558b393c2f11d5a580bbab48fb8b 100644 --- a/FTPClient/entry/src/main/ets/entryability/EntryAbility.ts +++ b/FTPClient/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; diff --git a/FTPClient/entry/src/main/ets/interfaces/NoTlsResultListener.ts b/FTPClient/entry/src/main/ets/interfaces/NoTlsResultListener.ts index 4aa8040273a92b8e105807dd308ffaa4813b480a..cb2778e3f4dce8e5c4e74aa09ef0fcea7f8fd1d7 100644 --- a/FTPClient/entry/src/main/ets/interfaces/NoTlsResultListener.ts +++ b/FTPClient/entry/src/main/ets/interfaces/NoTlsResultListener.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { FileInfo, FTPResponse } from '@ohos/basic-ftp' export interface LoginListener { diff --git a/FTPClient/entry/src/main/ets/pages/Index.ets b/FTPClient/entry/src/main/ets/pages/Index.ets index 2c008d583346dc8d861ad9c3c513e00dc2cd14bf..2570f6dd5c5e2f98a4cf826282030c2b2549c2ea 100644 --- a/FTPClient/entry/src/main/ets/pages/Index.ets +++ b/FTPClient/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import NoTlsUtil from '../utils/FtpApiUtil' import { AccessOptions, FileInfo, FileType, FTPResponse, UnixPermissions } from '@ohos/basic-ftp' import fs from '@ohos.file.fs' diff --git a/FTPClient/entry/src/main/ets/utils/FtpApiUtil.ts b/FTPClient/entry/src/main/ets/utils/FtpApiUtil.ts index f7232e4d12ac12896842b3cbc9d7ab33752c63c9..6edc1231ba62ada3b363093bd8daee48d61c1a87 100644 --- a/FTPClient/entry/src/main/ets/utils/FtpApiUtil.ts +++ b/FTPClient/entry/src/main/ets/utils/FtpApiUtil.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { AccessOptions, Client, FileInfo, FTPResponse, join, to } from '@ohos/basic-ftp' import fs from '@ohos.file.fs'; import { diff --git a/FTPClient/entry/src/main/resources/zh_CN/element/string.json b/FTPClient/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e61d7e30367c22fe2f8638008361b044..7bccef462b477b1b03faebc96aeba142339773c3 100644 --- a/FTPClient/entry/src/main/resources/zh_CN/element/string.json +++ b/FTPClient/entry/src/main/resources/zh_CN/element/string.json @@ -2,15 +2,15 @@ "string": [ { "name": "module_desc", - "value": "模块描述" + "value": "FTP" }, { "name": "EntryAbility_desc", - "value": "description" + "value": "FTP" }, { "name": "EntryAbility_label", - "value": "label" + "value": "FTP" } ] } \ No newline at end of file diff --git a/FTPClient/entry/src/ohosTest/ets/MockFtpServer.ets b/FTPClient/entry/src/ohosTest/ets/MockFtpServer.ets index b4d656ea55bba6ec8e6dbd3ed7449e9bca1f24f0..7777ecf5b937f2786b945b68b66cfd31c067f6d6 100644 --- a/FTPClient/entry/src/ohosTest/ets/MockFtpServer.ets +++ b/FTPClient/entry/src/ohosTest/ets/MockFtpServer.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // const net = require("net") import socket from '@ohos.net.socket'; import buffer from '@ohos.buffer'; diff --git a/FTPClient/entry/src/ohosTest/ets/test/Ability.test.ets b/FTPClient/entry/src/ohosTest/ets/test/Ability.test.ets index 140ca1a16ad4d54ee49a59ab1d06bac42b335eb8..37ed8efa87477e8edac79e8378303b17cba0b1f2 100644 --- a/FTPClient/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/FTPClient/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium' diff --git a/FTPClient/entry/src/ohosTest/ets/test/FTPClient.test.ets b/FTPClient/entry/src/ohosTest/ets/test/FTPClient.test.ets index e128b2d4029790a8906eba36b74583c952dfccd9..ce7169ea78dedcdf34695403632894e5e9cbd9a7 100644 --- a/FTPClient/entry/src/ohosTest/ets/test/FTPClient.test.ets +++ b/FTPClient/entry/src/ohosTest/ets/test/FTPClient.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium' import NoTlsUtil from '../../../../../entry/src/main/ets/utils/FtpApiUtil' import { AccessOptions, FileInfo, FileType, FTPResponse, UnixPermissions } from '@ohos/basic-ftp' diff --git a/FTPClient/entry/src/ohosTest/ets/test/List.test.ets b/FTPClient/entry/src/ohosTest/ets/test/List.test.ets index d140b959cb1a36baf74c338c98af8cd02b55c2cd..6978bb8a560f919be314d8ac92ab9c1c0602c804 100644 --- a/FTPClient/entry/src/ohosTest/ets/test/List.test.ets +++ b/FTPClient/entry/src/ohosTest/ets/test/List.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import FTPClientTest from './FTPClient.test' export default function testsuite() { diff --git a/FTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets b/FTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets index 0705f6232145431d746675566d11181fc0737bbf..02db7d2a82711d88a67bd61f0e6c8ac25a4b28ba 100644 --- a/FTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/FTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import hilog from '@ohos.hilog'; diff --git a/FTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets b/FTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets index 548db5c58417d58a945d7e5c0399aad41e36bf95..4b830e3aadacac77672ad0c8c897f20c01f3c6df 100644 --- a/FTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/FTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; @Entry diff --git a/FTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/FTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts index 834df45656de39ea0924a853fbf3942788d70b6b..4157a6f23872105bf4f8ee5acf691d89a8ed6a2f 100644 --- a/FTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ b/FTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import TestRunner from '@ohos.application.testRunner'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; diff --git a/IMAPClient/entry/src/main/ets/bean/MsgListBean.ets b/IMAPClient/entry/src/main/ets/bean/MsgListBean.ets index c1b4094adf9067965af11d61ea950c548c79e5cf..0df150a564a12d75b8b2f3cabea5f1e0e67a5f30 100644 --- a/IMAPClient/entry/src/main/ets/bean/MsgListBean.ets +++ b/IMAPClient/entry/src/main/ets/bean/MsgListBean.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + export default class MsgListBean { public Date: string = '' public From: string = '' diff --git a/IMAPClient/entry/src/main/ets/bean/StatusBean.ets b/IMAPClient/entry/src/main/ets/bean/StatusBean.ets index 66b46b855ce7cd7fdaed0f224eb868b196b0f017..e48bd4bde653f0b5f503cc70aee6afe8112e1142 100644 --- a/IMAPClient/entry/src/main/ets/bean/StatusBean.ets +++ b/IMAPClient/entry/src/main/ets/bean/StatusBean.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + class MessageItem { constructor() { } diff --git a/IMAPClient/entry/src/main/ets/entryability/EntryAbility.ts b/IMAPClient/entry/src/main/ets/entryability/EntryAbility.ts index 942957e316182c7ca900aeca78ec59740791fa4f..68bee7beefa2e14b0840632bcf6a8074ca176b48 100644 --- a/IMAPClient/entry/src/main/ets/entryability/EntryAbility.ts +++ b/IMAPClient/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; diff --git a/IMAPClient/entry/src/main/ets/pages/FolderPage.ets b/IMAPClient/entry/src/main/ets/pages/FolderPage.ets index 6c6b7017821eb8a00cd0850613f920a184633daa..976f1cfcbeab00587d4b38f8d037688090a2c6db 100644 --- a/IMAPClient/entry/src/main/ets/pages/FolderPage.ets +++ b/IMAPClient/entry/src/main/ets/pages/FolderPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import Imap, { inspect } from '@ohos/imap' import router from '@ohos.router' diff --git a/IMAPClient/entry/src/main/ets/pages/Index.ets b/IMAPClient/entry/src/main/ets/pages/Index.ets index 3b89321071cca72eee895fff3da1ca008f7323c8..cceb034a9b2f38717660ef89b1db2416906c6714 100644 --- a/IMAPClient/entry/src/main/ets/pages/Index.ets +++ b/IMAPClient/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import Imap, { inspect } from '@ohos/imap' import promptAction from '@ohos.promptAction' import router from '@ohos.router' diff --git a/IMAPClient/entry/src/main/ets/pages/LoginPage.ets b/IMAPClient/entry/src/main/ets/pages/LoginPage.ets index 6ea8c8491d1bab9291dde83b3c6f67139732f634..d6b42b10f5f5c0d4855b99a14113a4d27403856b 100644 --- a/IMAPClient/entry/src/main/ets/pages/LoginPage.ets +++ b/IMAPClient/entry/src/main/ets/pages/LoginPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import Imap, { inspect } from '@ohos/imap' import promptAction from '@ohos.promptAction' import router from '@ohos.router' diff --git a/IMAPClient/entry/src/main/ets/pages/MsgDetailPage.ets b/IMAPClient/entry/src/main/ets/pages/MsgDetailPage.ets index 4e291d39cd7c702fe53deee1e18da38b28a78d47..94b40a42cebe5cee8d683508e7cb8d422454d276 100644 --- a/IMAPClient/entry/src/main/ets/pages/MsgDetailPage.ets +++ b/IMAPClient/entry/src/main/ets/pages/MsgDetailPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import Imap, { inspect } from '@ohos/imap' import router from '@ohos.router' diff --git a/IMAPClient/entry/src/main/ets/pages/MsgListPage.ets b/IMAPClient/entry/src/main/ets/pages/MsgListPage.ets index aab02bf02eabb56f2be82608be1cc3591d751ab3..985e292976e843f6a8f8cb98db1a145038e1c3e4 100644 --- a/IMAPClient/entry/src/main/ets/pages/MsgListPage.ets +++ b/IMAPClient/entry/src/main/ets/pages/MsgListPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import Imap, { inspect } from '@ohos/imap' import router from '@ohos.router' diff --git a/IMAPClient/entry/src/main/ets/pages/TestInterfacePage.ets b/IMAPClient/entry/src/main/ets/pages/TestInterfacePage.ets index bd7bd56855b81cdaff23d54c3c3082661950b21e..694ab3203cc67a9df420dd2dc4d42064ba2eb28b 100644 --- a/IMAPClient/entry/src/main/ets/pages/TestInterfacePage.ets +++ b/IMAPClient/entry/src/main/ets/pages/TestInterfacePage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import Imap, { inspect } from '@ohos/imap' import socket from '@ohos.net.socket' diff --git a/IMAPClient/entry/src/main/resources/zh_CN/element/string.json b/IMAPClient/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e61d7e30367c22fe2f8638008361b044..d8e795489be99739f4ce26ff53d15fb86e3acb20 100644 --- a/IMAPClient/entry/src/main/resources/zh_CN/element/string.json +++ b/IMAPClient/entry/src/main/resources/zh_CN/element/string.json @@ -2,15 +2,15 @@ "string": [ { "name": "module_desc", - "value": "模块描述" + "value": "IMAP" }, { "name": "EntryAbility_desc", - "value": "description" + "value": "IMAP" }, { "name": "EntryAbility_label", - "value": "label" + "value": "IMAP" } ] } \ No newline at end of file diff --git a/IMAPClient/entry/src/ohosTest/ets/test/Ability.test.ets b/IMAPClient/entry/src/ohosTest/ets/test/Ability.test.ets index 8abf7f2f44c0e56110df8c09b2524a4ca37bc993..ef5e74bdbe1ac3737bb97ee9aaed5e2b72a7286a 100644 --- a/IMAPClient/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/IMAPClient/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' diff --git a/IMAPClient/entry/src/ohosTest/ets/test/List.test.ets b/IMAPClient/entry/src/ohosTest/ets/test/List.test.ets index d3b65141d11c466b36a65583f6b27745d456ce1b..8b5acd4a4296bb72128862602a399ed5a7d26ce0 100644 --- a/IMAPClient/entry/src/ohosTest/ets/test/List.test.ets +++ b/IMAPClient/entry/src/ohosTest/ets/test/List.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import abilityTest from './Ability.test' import SMTPClientTest from './SMTPClient.test' diff --git a/IMAPClient/entry/src/ohosTest/ets/test/SMTPClient.test.ets b/IMAPClient/entry/src/ohosTest/ets/test/SMTPClient.test.ets index 3cc6ec0b41826cdbd64959b73fe6a2b746eae6a0..1a89e928664539e9eca156b504381d35646896d8 100644 --- a/IMAPClient/entry/src/ohosTest/ets/test/SMTPClient.test.ets +++ b/IMAPClient/entry/src/ohosTest/ets/test/SMTPClient.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium' import promptAction from '@ohos.promptAction' diff --git a/POP3Client/CHANGELOG.md b/POP3Client/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..e3f5c2ffc4b122932251efdb0185caeb854308d7 --- /dev/null +++ b/POP3Client/CHANGELOG.md @@ -0,0 +1 @@ +1.支持pop3协议 \ No newline at end of file diff --git a/POP3Client/LICENSE b/POP3Client/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..5aabb26f2976e6c99ab3980bebe22c9b93157800 --- /dev/null +++ b/POP3Client/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 lian + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/POP3Client/OAT.xml b/POP3Client/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..fb23c1bacda5702134515b12df1256cdd07b640b --- /dev/null +++ b/POP3Client/OAT.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/POP3Client/README.OpenSource.md b/POP3Client/README.OpenSource.md new file mode 100644 index 0000000000000000000000000000000000000000..e7f42d641f9ae08965b8b371382cbfed9412f07b --- /dev/null +++ b/POP3Client/README.OpenSource.md @@ -0,0 +1,10 @@ +[ + { + "Name": "node-pop3", + "License": "MIT", + "Version Number": "0.9.0", + "Owner" : "xiafeng@huawei.com" + "Upstream URL": "https://github.com/node-pop3/node-pop3", + "Description": "pop3 command support for node. Supports Promise and stream" +} +] \ No newline at end of file diff --git a/POP3Client/README.md b/POP3Client/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4670fe434f4c14b4b6bad76d61429b3cfa873073 --- /dev/null +++ b/POP3Client/README.md @@ -0,0 +1,76 @@ +## POP3 + +### 介绍 + +支持pop3协议 + +### 下载 + +1丶安装 + +``` + ohpm install @ohos/node_pop3 +``` + +2丶导入 + +``` + import XXXX from '@ohos/node_pop3' +``` + +### Demo样例 + +参照该Demo工程中[Index](./entry/src/main/ets/pages/Index.ets)页面 + +单元测试用例详情见[TEST.md](./TEST.md) + +### 接口说明 + +API + +| 参数 | 可选 | 描述 | +|--------------------|-----|-------------------------------------------------------------------------| +| options.user | no | String | +| options.password | no | String | +| options.host | no | String | +| options.port | yes | Number. Defaults to 110 | +| options.servername | yes | String. Defaults to host value. Same as servername for Node TLS option. | +| options.tls | yes | Boolean. Defaults to false | +| options.timeout | yes | Number. Defaults to undefined | +| connect() | | connect | +| command(...args) | | send command messages | +| listify(str) | | converts each line to a an array based on splitting by spaces | +| UIDL(msgNumber = '') | | | +| RETR(msgNumber) | | | +| TOP(msgNumber, numLines = 0) | | | +| QUIT() | | | + + +### 软件架构 + +``` +|-entry + |-ets + | |-entryability + | |-EntryAbility.ts + | |-pages + | |-LoginPage.ets #主页demo + | |-SendMailPage.ets +|-POP3 # pop3协议lib +``` + +### 约束与限制 + +在下述版本验证通过: + +DevEco Studio: 4.0 Canary2(4.0.3.312), SDK: API10 (4.0.9.2) + +### 开源协议 + +本项目基于 [MIT license](./LICENSE) +,请自由地享受和参与开源。 + +### 贡献代码 + +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/issues) +给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/pulls) 。 \ No newline at end of file diff --git a/POP3Client/TEST.md b/POP3Client/TEST.md new file mode 100644 index 0000000000000000000000000000000000000000..a465aff8703ab305c4e464b1839c5fa3a1809a76 --- /dev/null +++ b/POP3Client/TEST.md @@ -0,0 +1,16 @@ +## pop3单元测试用例 + +该测试用例基于OpenHarmony系统下,进行单元测试 + +### 单元测试用例覆盖情况 + +|接口名 | 是否通过 |备注| +|---|---|---| +|LIST()|pass| +|STAT()|pass| +|NOOP()|pass| +|UIDL(msgNumber = '')|pass| +|DELE(...)|pass| +|RSET()|pass| +|RETR(msgNumber)|pass| +|QUIT()|pass| diff --git a/POP3Client/entry/src/main/ets/MsgBean.ts b/POP3Client/entry/src/main/ets/MsgBean.ts index 6e2b9211990bf5f87d75797d4adc833f537adf32..553274598f1a1d6aece60c4b5a5c79a4b76c6e1d 100644 --- a/POP3Client/entry/src/main/ets/MsgBean.ts +++ b/POP3Client/entry/src/main/ets/MsgBean.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + export default class MsgBean { private index: number; private size: number; diff --git a/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts b/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts index 8411c9ee39585e0a09d4d613099e185e31c76902..887db5a67e4301a01fd80b3290c99afff576d0ee 100644 --- a/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts +++ b/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; @@ -15,6 +30,7 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); globalThis.client = undefined + globalThis.context = this.context windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); diff --git a/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets index f6f59696cb1b8aace5c8714eb4d211847837d29a..6a10b7c7f885a2d5561a62fec2c70c5e57f508f8 100644 --- a/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets +++ b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import router from '@ohos.router' import Pop3Command from '@ohos/node_pop3' @@ -451,9 +466,9 @@ struct AutoLoginCommandPage { return } if (ctx.client) { - let delResult = ctx.client.DELE(ctx.selectMsgNum + '') - ctx.showToast('获取到RSETE命令的结果', 'sendRSET') - ctx.listData.push(`发送DELE命令删除的结果:${'\r\n'}${delResult}`) + // let delResult = ctx.client.DELE(ctx.selectMsgNum + '') + // ctx.showToast('获取到RSETE命令的结果', 'sendRSET') + // ctx.listData.push(`发送DELE命令删除的结果:${'\r\n'}${delResult}`) let startTime1 = new Date().getTime(); let result = await ctx.client.RSET() // 用于撤销DELE命令 所以不需要等DELE命令返回 let endTime1 = new Date().getTime(); @@ -523,7 +538,7 @@ struct AutoLoginCommandPage { console.log("QUIT averageTime : " + averageTime1 + "us") ctx.showToast('获取到QUIT命令的结果', 'sendQUIT') ctx.listData.push(`获取到QUIT命令的结果:${'\r\n'}${quitInfo}`) - + globalThis.context.terminateSelf() } else { ctx.listData.push(`账号未登录,请需重新登录`) ctx.showToast('账号未登录,请需重新登录', 'sendQUIT') diff --git a/POP3Client/entry/src/main/ets/pages/CommandPage.ets b/POP3Client/entry/src/main/ets/pages/CommandPage.ets index 48f658bee268703827c3a1378be017c59007366f..bd5569019c38fda0f31b54d06b5e55c5e80d14a8 100644 --- a/POP3Client/entry/src/main/ets/pages/CommandPage.ets +++ b/POP3Client/entry/src/main/ets/pages/CommandPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import router from '@ohos.router' import fs from '@ohos.file.fs'; diff --git a/POP3Client/entry/src/main/ets/pages/Index.ets b/POP3Client/entry/src/main/ets/pages/Index.ets index 73266727c4b03c34b099b58aa5434d132992c282..665d2591874500a76deb44816ab67fc291663a50 100644 --- a/POP3Client/entry/src/main/ets/pages/Index.ets +++ b/POP3Client/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import promptAction from '@ohos.promptAction' import router from '@ohos.router' import socket from '@ohos.net.socket' diff --git a/POP3Client/entry/src/main/ets/pages/TipsPage.ets b/POP3Client/entry/src/main/ets/pages/TipsPage.ets index 84946f3109b752c12e8d9d5cd7355d5166d41e76..43c4ece46e4f077ff5a2d8e9340f88771bdd79a4 100644 --- a/POP3Client/entry/src/main/ets/pages/TipsPage.ets +++ b/POP3Client/entry/src/main/ets/pages/TipsPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @Entry @Component struct TipsPage { diff --git a/POP3Client/entry/src/main/resources/zh_CN/element/string.json b/POP3Client/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e61d7e30367c22fe2f8638008361b044..d0a648f5af0c69e165e0e837915cb6b7e4665976 100644 --- a/POP3Client/entry/src/main/resources/zh_CN/element/string.json +++ b/POP3Client/entry/src/main/resources/zh_CN/element/string.json @@ -2,15 +2,15 @@ "string": [ { "name": "module_desc", - "value": "模块描述" + "value": "POP3" }, { "name": "EntryAbility_desc", - "value": "description" + "value": "POP3" }, { "name": "EntryAbility_label", - "value": "label" + "value": "POP3" } ] } \ No newline at end of file diff --git a/POP3Client/entry/src/ohosTest/ets/test/Ability.test.ets b/POP3Client/entry/src/ohosTest/ets/test/Ability.test.ets index 50f4ed64974de57912f20884065988c0a5175a13..7b970af59ad9f9c35869a9929b5706f612a37b6e 100644 --- a/POP3Client/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/POP3Client/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium' diff --git a/POP3Client/entry/src/ohosTest/ets/test/List.test.ets b/POP3Client/entry/src/ohosTest/ets/test/List.test.ets index 500d462b5a15064fe8a6d7397808e1772818e10a..ee82ae4da6d6aec0115329f7d62711adbb3d78ae 100644 --- a/POP3Client/entry/src/ohosTest/ets/test/List.test.ets +++ b/POP3Client/entry/src/ohosTest/ets/test/List.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import POP3Test from './POP3.test' export default function testsuite() { diff --git a/POP3Client/entry/src/ohosTest/ets/test/POP3.test.ets b/POP3Client/entry/src/ohosTest/ets/test/POP3.test.ets index 2b0c2a7fb5a5a78c1ca30418707fd7b505a70222..41738673915047827bfb8f31015a1423cef64faf 100644 --- a/POP3Client/entry/src/ohosTest/ets/test/POP3.test.ets +++ b/POP3Client/entry/src/ohosTest/ets/test/POP3.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium' import promptAction from '@ohos.promptAction' diff --git a/POP3Client/entry/src/ohosTest/ets/testability/TestAbility.ets b/POP3Client/entry/src/ohosTest/ets/testability/TestAbility.ets index 0705f6232145431d746675566d11181fc0737bbf..02db7d2a82711d88a67bd61f0e6c8ac25a4b28ba 100644 --- a/POP3Client/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/POP3Client/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import hilog from '@ohos.hilog'; diff --git a/POP3Client/entry/src/ohosTest/ets/testability/pages/Index.ets b/POP3Client/entry/src/ohosTest/ets/testability/pages/Index.ets index 548db5c58417d58a945d7e5c0399aad41e36bf95..4b830e3aadacac77672ad0c8c897f20c01f3c6df 100644 --- a/POP3Client/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/POP3Client/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; @Entry diff --git a/POP3Client/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/POP3Client/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts index 834df45656de39ea0924a853fbf3942788d70b6b..4157a6f23872105bf4f8ee5acf691d89a8ed6a2f 100644 --- a/POP3Client/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ b/POP3Client/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import TestRunner from '@ohos.application.testRunner'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; diff --git a/SMTPClient/CHANGELOG.md b/SMTPClient/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..35240a7ecaee4929f0ca120d1295930307b57e7e --- /dev/null +++ b/SMTPClient/CHANGELOG.md @@ -0,0 +1,2 @@ +### V2.0.0 +1.向任何 SMTP 服务器发送 HTML 电子邮件和附件 \ No newline at end of file diff --git a/SMTPClient/LICENSE b/SMTPClient/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..f98013c352e0fc0de598dc35923e6104f9b7a962 --- /dev/null +++ b/SMTPClient/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) <2011> + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/SMTPClient/OAT.xml b/SMTPClient/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..c788bf3791d5836038478d7e6c8e308d864f01de --- /dev/null +++ b/SMTPClient/OAT.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SMTPClient/README.OpenSource b/SMTPClient/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..67c6ae143dcb3fa76238868d052ff30972a1406c --- /dev/null +++ b/SMTPClient/README.OpenSource @@ -0,0 +1,10 @@ +[ + { + "Name": "emailjs", + "License": "MIT License", + "Version Number": "3.3.0", + "Owner" : "xiafeng@huawei.com" + "Upstream URL": "https://github.com/eleith/emailjs", + "Description": "html emails and attachments to any smtp server with nodejs" + } +] \ No newline at end of file diff --git a/SMTPClient/README.md b/SMTPClient/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f4d8defdbaa67459be1268042138d99438f2463f --- /dev/null +++ b/SMTPClient/README.md @@ -0,0 +1,143 @@ +## SMTP + +### 介绍 + +SMTP是一个基于OpenHarmony系统适配开发的,提供一个向任何 SMTP 服务器发送 HTML 电子邮件和附件的能力。 + +### 下载 + +``` + $ ohpm install @ohos/emailjs +``` + +OpenHarmony ohpm +环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) + +### 导入 + +``` + import { XXXXXXXX } from '@ohos/emailjs' +``` + +### 使用说明 + +参考该[Demo](./entry/src/main/ets/pages/LoginPage.ets)工程 + +### 接口说明 + +| 方法名 | 入参 | 接口描述 | +|:---------------------------------------------:|:---------------------------------:|:----------------:| +| new SMTPClient({options}) | options(参照如下 new SMTPClient 参数说明) | 创建SMTP客户端 | +| login(callBack: (err: Error, result: boolean) | (err: Error, result: boolean) | 登录 | +| SMTPClient#send(message, callback) | message, callback | 发送信息及其回调callback | +| new Message(headers) | headers(参照如下 new Message 参数说明) | 构建信息 | +| Message#attach(options) | options(参照如下 attach 参数说明) | 添加附件信息 | +| Message#checkValidity() | 无 | 验证消息格式是否正确 | +| new SMTPConnection(options={}) | options(参照如下 SMTPConnection 参数说明) | 构建SMTPC链接 | + +#### new SMTPClient 参数说明 + +``` + // options is an object with the following recognized schema: +const options = { + user, // username for logging into smtp + password, // password for logging into smtp + host, // smtp host (defaults to 'localhost') + port, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`) + ssl, // boolean or object (if true or object, ssl connection will be made) + tls, // boolean or object (if true or object, starttls will be initiated) + timeout, // max number of milliseconds to wait for smtp responses (defaults to 5000) + domain, // domain to greet smtp with (defaults to os.hostname) + authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2') + logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work) +}; +``` + +#### new Message 参数说明 + +``` +const headers = { + from, // sender of the format (address or name
or "name"
) + to, // recipients (same format as above), multiple recipients are separated by a comma + cc, // carbon copied recipients (same format as above) + bcc, // blind carbon copied recipients (same format as above) + text, // text of the email + subject, // string subject of the email + attachment, // one attachment or array of attachments +}; +``` + +#### attach 参数说明 + +``` +const options = { + // one of these fields is required + path, // string to where the file is located + data, // string of the data you want to attach + stream, // binary stream that will provide attachment data (make sure it is in the paused state) + // better performance for binary streams is achieved if buffer.length % (76*6) == 0 + // current max size of buffer must be no larger than Message.BUFFERSIZE + + // optionally these fields are also accepted + type, // string of the file mime type + name, // name to give the file as perceived by the recipient + charset, // charset to encode attatchment in + method, // method to send attachment as (used by calendar invites) + alternative, // if true, will be attached inline as an alternative (also defaults type='text/html') + inline, // if true, will be attached inline + encoded, // set this to true if the data is already base64 encoded, (avoid this if possible) + headers, // object containing header=>value pairs for inclusion in this attachment's header + related, // an array of attachments that you want to be related to the parent attachment +}; +``` + +#### SMTPConnection 参数说明 + +``` +const options = { + user, // username for logging into smtp + password, // password for logging into smtp + host, // smtp host (defaults to 'localhost') + port, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`) + ssl, // boolean or object (if true or object, ssl connection will be made) + tls, // boolean or object (if true or object, starttls will be initiated) + timeout, // max number of milliseconds to wait for smtp responses (defaults to 5000) + domain, // domain to greet smtp with (defaults to os.hostname) + authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2') + logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work) +}; +``` + +### 软件架构 + +``` +|-entry + |-ets + | |-entryability + | |-EntryAbility.ts + | |-pages + | |-LoginPage.ets #主页demo + | |-SendMailPage.ets +|-SMTP + |-ets # + |-js # + +``` + +### 单元测试用例详情[TEST.md](./TEST.md) + +### 约束与限制 + +在下述版本验证通过: + +DevEco Studio: 4.0 Canary2(4.0.3.312), SDK: API10 (4.0.9.2) + +### 开源协议 + +本项目基于 [MIT license](./LICENSE) +,请自由地享受和参与开源。 + +### 贡献代码 + +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/issues) +给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/pulls) 。 \ No newline at end of file diff --git a/SMTPClient/TEST.md b/SMTPClient/TEST.md new file mode 100644 index 0000000000000000000000000000000000000000..dc4a5d7d9210471351fe7b44bd8f03f1dd7aa3f9 --- /dev/null +++ b/SMTPClient/TEST.md @@ -0,0 +1,15 @@ +## SMTPClient单元测试用例 + +该测试用例基于OpenHarmony系统下,参照[原库测试用例](https://github.com/eleith/emailjs/tree/main/test) 进行单元测试 + +### 单元测试用例覆盖情况 + +| 接口名 | 是否通过 |备注| +|--------------------------------|---|---| +| addressparser(address?: string | pass|| +| new SMTPConnection |pass| +| getRFC2822Date |pass| +| getRFC2822DateUTC |pass| +| isRFC2822Date |pass| +| mimeEncode |pass| +| mimeWordEncode |pass| \ No newline at end of file diff --git a/SMTPClient/build-profile.json5 b/SMTPClient/build-profile.json5 index efdcc4ad8e4f77abb19b60f30de1dada292f0c37..38b8cf8b316c76a795a87e44cde867c4bababb35 100644 --- a/SMTPClient/build-profile.json5 +++ b/SMTPClient/build-profile.json5 @@ -5,7 +5,7 @@ "products": [ { "name": "default", - "signingConfig": "default", + "signingConfig": "default" } ] }, diff --git a/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts b/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts index 11f880eb5a4dad7f53e81061ab22788a184c9da5..6aee93d3841ae2fe460a2070621da54d42d72821 100644 --- a/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts +++ b/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; @@ -15,6 +30,7 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); globalThis.client = undefined + globalThis.context = this.context windowStage.loadContent('pages/LoginPage', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); diff --git a/SMTPClient/entry/src/main/ets/pages/LoginPage.ets b/SMTPClient/entry/src/main/ets/pages/LoginPage.ets index 466bce703af6542db9ebd290aec29238b8c8ec3a..c8dc2cce37bc2a89a8a143e49098bbf8753ef587 100644 --- a/SMTPClient/entry/src/main/ets/pages/LoginPage.ets +++ b/SMTPClient/entry/src/main/ets/pages/LoginPage.ets @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { AUTH_METHODS, SMTPClient } from '@ohos/emailjs' import promptAction from '@ohos.promptAction' import router from '@ohos.router' diff --git a/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets b/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets index e6005b44cb199175ceffac2eb202782ced3914e2..52df92f85725d9c147da4bc182ff56be0369b0b8 100644 --- a/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets +++ b/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import promptAction from '@ohos.promptAction' import router from '@ohos.router' import { Message, MessageAttachment, MessageHeaders } from '@ohos/emailjs' @@ -518,4 +532,9 @@ struct SendMailPage { return false; } } + + onBackPress(){ + globalThis.context.terminateSelf() + } + } \ No newline at end of file diff --git a/SMTPClient/entry/src/main/resources/zh_CN/element/string.json b/SMTPClient/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e61d7e30367c22fe2f8638008361b044..f619890948791b7c8fa97ea26533fb8727436b27 100644 --- a/SMTPClient/entry/src/main/resources/zh_CN/element/string.json +++ b/SMTPClient/entry/src/main/resources/zh_CN/element/string.json @@ -2,15 +2,15 @@ "string": [ { "name": "module_desc", - "value": "模块描述" + "value": "SMTP" }, { "name": "EntryAbility_desc", - "value": "description" + "value": "SMTP" }, { "name": "EntryAbility_label", - "value": "label" + "value": "SMTP" } ] } \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/Ability.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Ability.test.ets index 8abf7f2f44c0e56110df8c09b2524a4ca37bc993..ef5e74bdbe1ac3737bb97ee9aaed5e2b72a7286a 100644 --- a/SMTPClient/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/SMTPClient/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' diff --git a/SMTPClient/entry/src/ohosTest/ets/test/Address.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Address.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d260cfbd9a2d9aafa59fee18e019a3594576d8e --- /dev/null +++ b/SMTPClient/entry/src/ohosTest/ets/test/Address.test.ets @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium' +import { addressparser } from '@ohos/emailjs' + +export default function addressTest() { + describe('addressTest', function () { + it('addressparser_should_handle_single_address_correctly', 0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let resukt = [ + { + address: 'andris@tr.ee', name: '' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris@tr.ee')) + }) + + + it('addressparser_should_handle_multiple_addresses_correctly', 0, function () { + let resukt = [ + { + address: 'andris@tr.ee', name: '' + }, + { + address: 'andris@example.com', name: '' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris@tr.ee, andris@example.com')) + }) + + it('addressparser_should_handle_unquoted_name_correctly', 0, function () { + let resukt = [ + { + name: 'andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris ')) + }) + + + it('addressparser_should_handle_quoted_name_correctly', 0, function () { + let resukt = [ + { + name: 'reinman, andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('"reinman, andris" ')) + }) + + it('addressparser_should_handle_quoted_semicolons_correctly', 0, function () { + let resukt = [ + { + name: 'reinman; andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('"reinman; andris" ')) + }) + + it('addressparser_should_handle_unquoted_name_unquoted_address_correctly', 0, function () { + let resukt = [ + { + name: 'andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris andris@tr.ee')) + }) + + it('addressparser_should_handle_empty_group_correctly', 0, function () { + let resukt = [ + { + name: 'Undisclosed', group: [] + }, + ] + expect(resukt).assertDeepEquals(addressparser('Undisclosed:;')) + }) + + it('addressparser_should_handle_address_group_correctly', 0, function () { + let resukt = [ + { + name: 'Disclosed', + group: [ + { + address: 'andris@tr.ee', name: '' + }, + { + address: 'andris@example.com', name: '' + }, + ], + }, + ] + expect(resukt).assertDeepEquals(addressparser('Disclosed:andris@tr.ee, andris@example.com;')) + }) + + + it('addressparser_should_handle_semicolon_as_a_delimiter', 0, function () { + let resukt = [ + { + address: 'andris@tr.ee', name: '' + }, + { + address: 'andris@example.com', name: '' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris@tr.ee; andris@example.com;')) + }) + + it('addressparser_should_handle_mixed_group_correctly', 0, function () { + let resukt = [ + { + address: 'test.user@mail.ee', name: 'Test User' + }, + { + name: 'Disclosed', + group: [ + { + address: 'andris@tr.ee', name: '' + }, + { + address: 'andris@example.com', name: '' + }, + ], + }, + { + name: 'Undisclosed', group: [] + }, + ] + expect(resukt).assertDeepEquals(addressparser( + 'Test User , Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:;' + )) + }) + + + it('addressparser_semicolon_as_delimiter_should_not_break_group_parsing', 0, function () { + let resukt = [ + { + address: 'test.user@mail.ee', name: 'Test User' + }, + { + name: 'Disclosed', + group: [ + { + address: 'andris@tr.ee', + name: '', + }, + { + address: 'andris@example.com', + name: '', + }, + ], + }, + { + name: 'Undisclosed', group: [] + }, + { + address: 'bob@example.com', name: '' + }, + ] + expect(resukt).assertDeepEquals(addressparser( + 'Test User ; Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:; bob@example.com;' + )) + }) + + + it('addressparser_should_handle_name_from_comment_correctly', 0, function () { + let resukt = [ + { + name: 'andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris@tr.ee (andris)')) + }) + + + it('addressparser_should_handle_skip_comment_correctly', 0, function () { + let resukt = [ + { + name: 'andris', address: 'andris@tr.ee' + }, + ] + expect(resukt).assertDeepEquals(addressparser('andris@tr.ee (reinman) andris')) + }) + + + it('addressparser_should_handle_missing_address_correctly', 0, function () { + let resukt = [{ + name: 'andris', address: '' + }] + expect(resukt).assertDeepEquals(addressparser('andris')) + }) + + + it('addressparser_should_handle_apostrophe_in_name_correctly', 0, function () { + let resukt = [{ + name: "O'Neill", address: '' + }] + expect(resukt).assertDeepEquals(addressparser("O'Neill")) + }) + + it('addressparser_should_handle_particularly_bad_input_unescaped_colon_correctly', 0, function () { + let resukt = [ + { + name: 'FirstName Surname-WithADash', + group: [ + { + name: undefined, + group: [{ + address: 'firstname@company.com', name: 'Company' + }], + }, + ], + }, + ] + expect(resukt).assertDeepEquals(addressparser( + 'FirstName Surname-WithADash :: Company ' + )) + }) + + }) +} \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/Connection.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Connection.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d68eca1cf693f089d82685b020259d2dd1e2c21f --- /dev/null +++ b/SMTPClient/entry/src/ohosTest/ets/test/Connection.test.ets @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium' +import { SMTPConnection } from '@ohos/emailjs' + + +export default function connectionTest() { + describe('connectionTest', function () { + it('accepts_a_custom_logger', 0, function () { + const logger = () => { + /** ø */ + }; + const connection = new SMTPConnection({ + logger + }); + expect(logger).assertEqual(Reflect.get(connection, 'log')); + }) + }) +} \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/Date.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Date.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..927d211e552130011e374fa140ff7ea7505b6aa4 --- /dev/null +++ b/SMTPClient/entry/src/ohosTest/ets/test/Date.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium' +import { getRFC2822Date, getRFC2822DateUTC, isRFC2822Date } from '@ohos/emailjs' + +const toD_utc = (dt: number) => getRFC2822DateUTC(new Date(dt)); +const toD = (dt: number, utc = false) => getRFC2822Date(new Date(dt), utc); + +export default function dateTest() { + describe('dateTest', function () { + it('rfc2822_non_UTC', 0, function () { + expect(isRFC2822Date(toD(0))).assertTrue(); + expect(isRFC2822Date(toD(329629726785))).assertTrue(); + expect(isRFC2822Date(toD(729629726785))).assertTrue(); + expect(isRFC2822Date(toD(1129629726785))).assertTrue(); + expect(isRFC2822Date(toD(1529629726785))).assertTrue(); + }) + + + it('rfc2822_UTC', 0, function () { + expect('Thu, 01 Jan 1970 00:00:00 +0000').assertEqual(toD_utc(0)); + expect(toD(0, true)).assertEqual(toD_utc(0)); + + expect('Thu, 12 Jun 1980 03:48:46 +0000').assertEqual(toD_utc(329629726785)); + expect(toD(329629726785, true)).assertEqual(toD_utc(329629726785)); + + expect('Sat, 13 Feb 1993 18:55:26 +0000').assertEqual(toD_utc(729629726785)); + expect(toD(729629726785, true)).assertEqual(toD_utc(729629726785)); + + expect('Tue, 18 Oct 2005 10:02:06 +0000').assertEqual(toD_utc(1129629726785)); + expect(toD(1129629726785, true)).assertEqual(toD_utc(1129629726785)); + + expect('Fri, 22 Jun 2018 01:08:46 +0000').assertEqual(toD_utc(1529629726785)); + expect(toD(1529629726785, true)).assertEqual(toD_utc(1529629726785)); + + }) + + }) +} \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/List.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/List.test.ets index f59b1be64a3bb3543c60847f5f08e85bbb0c71c8..277027cd62a9f8763a2c32d91fec837cda1df31f 100644 --- a/SMTPClient/entry/src/ohosTest/ets/test/List.test.ets +++ b/SMTPClient/entry/src/ohosTest/ets/test/List.test.ets @@ -1,5 +1,26 @@ -import SMTPTest from './SMTP.test' +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import addressTest from './Address.test' +import connectionTest from './Connection.test' +import dateTest from './Date.test' +import mimeTest from './Mime.test' export default function testsuite() { - SMTPTest() + addressTest() + connectionTest() + dateTest() + mimeTest() } \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/Mime.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Mime.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..48378bc87d1394aa8988fe416738ecfd452ff56f --- /dev/null +++ b/SMTPClient/entry/src/ohosTest/ets/test/Mime.test.ets @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium' +import { mimeEncode, mimeWordEncode } from '@ohos/emailjs' + + +export default function mimeTest() { + describe('mimeTest', function () { + it('mimeEncode_should_encode_UTF_8', 0, function () { + expect("tere =C3=95=C3=84=C3=96=C3=95").assertEqual(mimeEncode('tere ÕÄÖÕ')); + }) + + it('mimeEncode_should_encode_trailing_whitespace', 0, function () { + expect('tere =20').assertEqual(mimeEncode('tere ')); + }) + + + it('mimeEncode_should_encode_non_UTF_8', 0, function () { + expect('=EB=B7=85').assertEqual(mimeEncode(new Uint8Array([0xbd, 0xc5]), 'utf-16be')); + }) + + it('mimeWordEncode_should_encode', 0, function () { + expect('=?UTF-8?Q?See_on_=C3=B5hin_test?=').assertEqual(mimeWordEncode('See on õhin test')); + }) + + it('mimeWordEncode_should_QP_encode_mime_word', 0, function () { + expect('=?UTF-8?Q?=E4=AB=B5=E6=9D=A5=E2=B5=B6=E6=87=9E?=').assertEqual(mimeWordEncode( + new Uint8Array([0x4a, 0xf5, 0x67, 0x65, 0x2d, 0x76, 0x61, 0xde]), + 'Q', + 'utf-16be' + )); + }) + + it('mimeWordEncode_should_Base64_encode_mime_word', 0, function () { + expect('=?UTF-8?B?0J/RgNC40LLQtdGCINC4INC00L4g0YHQstC40LTQsNC90LjRjw==?=') + .assertEqual(mimeWordEncode('Привет и до свидания', 'B')); + }) + + it('mimeWordEncode_should_Base64_encode_a_long_mime_word', 0, function () { + const payload = + 'üöß‹€Привет и до свиданияПривет и до свиданияПривет и до свиданияПривет и до свиданияПривет и до свиданияПривет и до свиданияПривет и до свиданияПривет и до свидания'; + const expected = + '=?UTF-8?B?w7zDtsOf4oC54oKs0J/RgNC40LLQtdGCINC4INC00L4g0YHQstC4?= ' + + '=?UTF-8?B?0LTQsNC90LjRj9Cf0YDQuNCy0LXRgiDQuCDQtNC+INGB0LLQuNC0?= ' + + '=?UTF-8?B?0LDQvdC40Y/Qn9GA0LjQstC10YIg0Lgg0LTQviDRgdCy0LjQtNCw?= ' + + '=?UTF-8?B?0L3QuNGP0J/RgNC40LLQtdGCINC4INC00L4g0YHQstC40LTQsNC9?= ' + + '=?UTF-8?B?0LjRj9Cf0YDQuNCy0LXRgiDQuCDQtNC+INGB0LLQuNC00LDQvdC4?= ' + + '=?UTF-8?B?0Y/Qn9GA0LjQstC10YIg0Lgg0LTQviDRgdCy0LjQtNCw0L3QuNGP?= ' + + '=?UTF-8?B?0J/RgNC40LLQtdGCINC4INC00L4g0YHQstC40LTQsNC90LjRj9Cf?= ' + + '=?UTF-8?B?0YDQuNCy0LXRgiDQuCDQtNC+INGB0LLQuNC00LDQvdC40Y8=?='; + + expect(expected).assertEqual(mimeWordEncode(payload, 'B')); + }) + + }) +} \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/test/SMTP.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/SMTP.test.ets deleted file mode 100644 index 929fec6749f2e5cecd2d49aeecc2f91711919c61..0000000000000000000000000000000000000000 --- a/SMTPClient/entry/src/ohosTest/ets/test/SMTP.test.ets +++ /dev/null @@ -1,227 +0,0 @@ -import hilog from '@ohos.hilog'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import { AUTH_METHODS, SMTPClient } from '@ohos/emailjs' -import promptAction from '@ohos.promptAction' -import router from '@ohos.router' -import socket from '@ohos.net.socket' -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import { Message, MessageHeaders, MessageAttachment } from '@ohos/emailjs' -import fs from '@ohos.file.fs'; - -export default function SMTPTest() { - - let message = 'Hello World' - let account = '479868299' - let password = 'zkljojjdatjrbgcg' - let mailType = '@qq.com' - let textValue = '' - let inputValue = 'click me' - let secure = false - let attachment: Array = [] - const BASE_COUNT = 1 - - - beforeAll(function (done) { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - loginmail(done) - createAttachment() - }) - - async function loginmail(done) { - try { - if (!globalThis.client) { - let client: SMTPClient = undefined; - if (secure) { - let option: socket.TLSConnectOptions = { - ALPNProtocols: ["spdy/1", "http/1.1"], - address: { - address: 'smtp.qq.com', - port: 465, - family: 1 - }, - secureOptions: { - key: '', - cert: '', - ca: [''], - useRemoteCipherPrefer: true, - } - } - let context: Context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext() - let ca0Data = await context.resourceManager.getRawFileContent('QQMailMiddle.pem') - let ca0 = ''; - for (let i = 0; i < ca0Data.length; i++) { - let todo = ca0Data[i] - let item = String.fromCharCode(todo); - ca0 += item; - } - // @ts-ignore - option.secureOptions.ca[0] = ca0; - - let ca1Data = await context.resourceManager.getRawFileContent('QQMailRoot.pem') - let ca1 = ''; - for (let i = 0; i < ca1Data.length; i++) { - let todo = ca1Data[i] - let item = String.fromCharCode(todo); - ca1 += item; - } - // @ts-ignore - option.secureOptions.ca[1] = ca1; - - client = new SMTPClient({ - user: '479868299@qq.com', - password: 'zkljojjdatjrbgcg', - host: 'smtp.qq.com', - port: 465, - timeout: 30000, - authentication: [AUTH_METHODS.LOGIN], - ssl: option, - tls: undefined - }); - } else { - client = new SMTPClient({ - user: '479868299@qq.com', - password: 'zkljojjdatjrbgcg', - host: 'smtp.qq.com', - port: 25, - timeout: 30000, - authentication: [AUTH_METHODS.LOGIN], - ssl: false, - tls: undefined - }); - } - globalThis.client = client - } - if (globalThis.client) { - if (!globalThis.client.isLogin()) { - globalThis.client.login((err, result) => { - done() - }) - } - } - } catch (err) { - done() - } - } - - - function createAttachment() { - try { - if (attachment && attachment.length == 0) { - let context: Context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext() - let randomNum = Math.round(Math.random() * 1024 + 1); - let filePath = context.cacheDir + '/' + 'attachment-' + randomNum + '.txt' - let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE) - let str = "客户端发送到服务端的信息,请查收\r\n" - fs.writeSync(file.fd, str) - fs.fsyncSync(file.fd) - fs.closeSync(file) - let attach: MessageAttachment = { - name: 'attachment-' + randomNum + '.txt', - path: filePath, - type: '.txt', - size: str.length - } - attachment.push(attach) - } else if (attachment && attachment.length == 1) { - let context: Context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext() - let filePath = context.cacheDir + '/test.jpg' - context.resourceManager.getRawFileContent('test.jpg').then((imageData) => { - if (imageData) { - let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE) - fs.writeSync(file.fd, imageData.buffer) - fs.fsyncSync(file.fd) - fs.closeSync(file) - let attach: MessageAttachment = { - name: 'test.jpg', - path: filePath, - type: 'jpg', - size: imageData.buffer.byteLength - } - attachment.push(attach) - } else { - expect(0).assertEqual(1) - } - }).catch((err: Error) => { - expect(0).assertEqual(1) - }) - } else if (attachment && attachment.length == 2) { - let context: Context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext() - let filePath = context.cacheDir + '/test.docx' - context.resourceManager.getRawFileContent('test.docx').then((wordData) => { - if (wordData) { - let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE) - fs.writeSync(file.fd, wordData.buffer) - fs.fsyncSync(file.fd) - fs.closeSync(file) - let attach: MessageAttachment = { - name: 'test.docx', - path: filePath, - type: 'docx', - size: wordData.buffer.byteLength - } - attachment.push(attach) - } else { - expect(0).assertEqual(1) - } - }).catch((err: Error) => { - expect(0).assertEqual(1) - }) - } else if (attachment && attachment.length == 3) { - let context: Context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext() - let filePath = context.cacheDir + '/test.xlsx' - context.resourceManager.getRawFileContent('test.xlsx').then((excelData) => { - if (excelData) { - let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE) - fs.writeSync(file.fd, excelData.buffer) - fs.fsyncSync(file.fd) - fs.closeSync(file) - let attach: MessageAttachment = { - name: 'test.xlsx', - path: filePath, - type: 'xlsx', - size: excelData.buffer.byteLength - } - attachment.push(attach) - } else { - expect(0).assertEqual(1) - } - }).catch((err: Error) => { - expect(0).assertEqual(1) - }) - } else { - expect(0).assertEqual(1) - } - - } catch (err) { - expect(0).assertEqual(1) - } - } - - - describe('SMTPTest', function () { - it('sendMail', 0, async function (done) { - try { - let msg: Message | MessageHeaders = { - text: '鸿蒙客户端发送的邮件内容,哈哈哈哈哈哈哈', - from: '软通测试 <479868299@qq.com>', - to: '赵先生 <479868299@qq.com>', - cc: 'else ', - bcc: 'else ', - subject: '鸿蒙客户端邮件主题', - attachment: attachment - } - let startTime1 = new Date().getTime(); - const message = await globalThis.client.sendAsync(msg) - let endTime1 = new Date().getTime(); - let averageTime1 = ((endTime1 - startTime1) * 1000) / BASE_COUNT; - console.log("SMTPTest : sendMail averageTime : " + averageTime1 + "us") - done() - } catch (err) { - expect(0).assertContain(1) - done() - } - }) - - }) -} \ No newline at end of file diff --git a/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets b/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets index e3f6e911d3fffba1e1795c60ed1ee4db15b386fd..e0bf1400d446892c012aa51c4da9c7942d1693ea 100644 --- a/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import UIAbility from '@ohos.app.ability.UIAbility'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import hilog from '@ohos.hilog'; diff --git a/SMTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets b/SMTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets index 166366593a7e55ef17e6619f68a4c46214814858..ab6dda5e44712568a67befdc5fb27e5f7621d5a8 100644 --- a/SMTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/SMTPClient/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; @Entry diff --git a/SMTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/SMTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts index 92a16d84e8870da219c51d9f1342c79203c1f42d..f6d93ba271bf50380f2bffd4f935d3bf591d8939 100644 --- a/SMTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ b/SMTPClient/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import hilog from '@ohos.hilog'; import TestRunner from '@ohos.application.testRunner'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';