From 061ebf5a10095639f303d4534ac8963f86bf8ae2 Mon Sep 17 00:00:00 2001 From: wupingyuan Date: Thu, 31 Aug 2023 10:29:29 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8DQUIT=E5=92=8C=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- POP3Client/entry/src/main/ets/entryability/EntryAbility.ts | 1 + POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets | 2 +- SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts | 1 + SMTPClient/entry/src/main/ets/pages/SendMailPage.ets | 5 +++++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts b/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts index 8411c9e..a2e3286 100644 --- a/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts +++ b/POP3Client/entry/src/main/ets/entryability/EntryAbility.ts @@ -15,6 +15,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 f6f5969..25af031 100644 --- a/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets +++ b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets @@ -523,7 +523,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/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts b/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts index 11f880e..8a7aef0 100644 --- a/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts +++ b/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts @@ -15,6 +15,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/SendMailPage.ets b/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets index 6c362f4..c9aa679 100644 --- a/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets +++ b/SMTPClient/entry/src/main/ets/pages/SendMailPage.ets @@ -520,4 +520,9 @@ struct SendMailPage { return false; } } + + onBackPress(){ + globalThis.context.terminateSelf() + } + } \ No newline at end of file -- Gitee From 6adb63f49be3d37a0310805593e03098a4dfb327 Mon Sep 17 00:00:00 2001 From: wupingyuan Date: Thu, 31 Aug 2023 11:10:50 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9RSET=E5=92=8Capp=E5=90=8D?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/resources/zh_CN/element/string.json | 6 +++--- .../entry/src/main/ets/pages/AutoLoginCommandPage.ets | 6 +++--- .../entry/src/main/resources/zh_CN/element/string.json | 6 +++--- .../entry/src/main/resources/zh_CN/element/string.json | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) 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 597ecf9..d8e7954 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/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets index 25af031..1232553 100644 --- a/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets +++ b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets @@ -451,9 +451,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(); 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 597ecf9..d0a648f 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/SMTPClient/entry/src/main/resources/zh_CN/element/string.json b/SMTPClient/entry/src/main/resources/zh_CN/element/string.json index 597ecf9..f619890 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 -- Gitee From d562afc03519c970ffd78f8f1a79af3901d81988 Mon Sep 17 00:00:00 2001 From: wupingyuan Date: Thu, 31 Aug 2023 14:37:50 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9SMTP=20XTS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMTPClient/build-profile.json5 | 2 +- .../src/ohosTest/ets/test/Ability.test.ets | 15 ++ .../src/ohosTest/ets/test/Address.test.ets | 232 ++++++++++++++++++ .../src/ohosTest/ets/test/Connection.test.ets | 32 +++ .../entry/src/ohosTest/ets/test/Date.test.ets | 52 ++++ .../entry/src/ohosTest/ets/test/List.test.ets | 25 +- .../entry/src/ohosTest/ets/test/Mime.test.ets | 69 ++++++ .../entry/src/ohosTest/ets/test/SMTP.test.ets | 227 ----------------- 8 files changed, 424 insertions(+), 230 deletions(-) create mode 100644 SMTPClient/entry/src/ohosTest/ets/test/Address.test.ets create mode 100644 SMTPClient/entry/src/ohosTest/ets/test/Connection.test.ets create mode 100644 SMTPClient/entry/src/ohosTest/ets/test/Date.test.ets create mode 100644 SMTPClient/entry/src/ohosTest/ets/test/Mime.test.ets delete mode 100644 SMTPClient/entry/src/ohosTest/ets/test/SMTP.test.ets diff --git a/SMTPClient/build-profile.json5 b/SMTPClient/build-profile.json5 index efdcc4a..38b8cf8 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/ohosTest/ets/test/Ability.test.ets b/SMTPClient/entry/src/ohosTest/ets/test/Ability.test.ets index 8abf7f2..ef5e74b 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 0000000..0d260cf --- /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 0000000..d68eca1 --- /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 0000000..927d211 --- /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 f59b1be..277027c 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 0000000..48378bc --- /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 929fec6..0000000 --- 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 -- Gitee From ecc44fb622095fdc27b94239df8a136555f7189b Mon Sep 17 00:00:00 2001 From: wupingyuan Date: Thu, 31 Aug 2023 14:39:27 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9FTP=E7=9A=84app=E5=90=8D?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/resources/zh_CN/element/string.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 597ecf9..7bccef4 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 -- Gitee From f06fd25c7c2f2292e3b6396d2aa9f63035eea05a Mon Sep 17 00:00:00 2001 From: wupingyuan Date: Thu, 31 Aug 2023 14:51:02 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9D=83?= =?UTF-8?q?=E5=92=8CREAME=E3=80=81CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FTPClient/CHANGELOG.md | 5 + FTPClient/LICENSE.txt | 19 + FTPClient/NOTICE | 34 + FTPClient/README.OpenSource | 11 + FTPClient/README.md | 588 ++++++++++++++++++ .../src/main/ets/entryability/EntryAbility.ts | 15 + .../ets/interfaces/NoTlsResultListener.ts | 15 + FTPClient/entry/src/main/ets/pages/Index.ets | 15 + .../entry/src/main/ets/utils/FtpApiUtil.ts | 15 + .../entry/src/ohosTest/ets/MockFtpServer.ets | 15 + .../src/ohosTest/ets/test/Ability.test.ets | 15 + .../src/ohosTest/ets/test/FTPClient.test.ets | 15 + .../entry/src/ohosTest/ets/test/List.test.ets | 15 + .../ohosTest/ets/testability/TestAbility.ets | 15 + .../ohosTest/ets/testability/pages/Index.ets | 15 + .../ets/testrunner/OpenHarmonyTestRunner.ts | 15 + .../entry/src/main/ets/bean/MsgListBean.ets | 15 + .../entry/src/main/ets/bean/StatusBean.ets | 15 + .../src/main/ets/entryability/EntryAbility.ts | 15 + .../entry/src/main/ets/pages/FolderPage.ets | 15 + IMAPClient/entry/src/main/ets/pages/Index.ets | 15 + .../entry/src/main/ets/pages/LoginPage.ets | 15 + .../src/main/ets/pages/MsgDetailPage.ets | 15 + .../entry/src/main/ets/pages/MsgListPage.ets | 15 + .../src/main/ets/pages/TestInterfacePage.ets | 15 + .../src/ohosTest/ets/test/Ability.test.ets | 15 + .../entry/src/ohosTest/ets/test/List.test.ets | 15 + .../src/ohosTest/ets/test/SMTPClient.test.ets | 15 + POP3Client/CHANGELOG.md | 1 + POP3Client/LICENSE | 21 + POP3Client/OAT.xml | 47 ++ POP3Client/README.OpenSource.md | 10 + POP3Client/README.md | 76 +++ POP3Client/TEST.md | 16 + POP3Client/entry/src/main/ets/MsgBean.ts | 15 + .../src/main/ets/entryability/EntryAbility.ts | 15 + .../main/ets/pages/AutoLoginCommandPage.ets | 15 + .../entry/src/main/ets/pages/CommandPage.ets | 15 + POP3Client/entry/src/main/ets/pages/Index.ets | 15 + .../entry/src/main/ets/pages/TipsPage.ets | 15 + .../src/ohosTest/ets/test/Ability.test.ets | 15 + .../entry/src/ohosTest/ets/test/List.test.ets | 15 + .../entry/src/ohosTest/ets/test/POP3.test.ets | 15 + .../ohosTest/ets/testability/TestAbility.ets | 15 + .../ohosTest/ets/testability/pages/Index.ets | 15 + .../ets/testrunner/OpenHarmonyTestRunner.ts | 15 + SMTPClient/CHANGELOG.md | 2 + SMTPClient/LICENSE | 19 + SMTPClient/OAT.xml | 44 ++ SMTPClient/README.OpenSource | 10 + SMTPClient/README.md | 143 +++++ SMTPClient/TEST.md | 15 + .../src/main/ets/entryability/EntryAbility.ts | 15 + .../entry/src/main/ets/pages/LoginPage.ets | 14 + .../entry/src/main/ets/pages/SendMailPage.ets | 14 + .../ohosTest/ets/testability/TestAbility.ets | 15 + .../ohosTest/ets/testability/pages/Index.ets | 15 + .../ets/testrunner/OpenHarmonyTestRunner.ts | 15 + 58 files changed, 1674 insertions(+) create mode 100644 FTPClient/CHANGELOG.md create mode 100644 FTPClient/LICENSE.txt create mode 100644 FTPClient/NOTICE create mode 100644 FTPClient/README.OpenSource create mode 100644 FTPClient/README.md create mode 100644 POP3Client/CHANGELOG.md create mode 100644 POP3Client/LICENSE create mode 100644 POP3Client/OAT.xml create mode 100644 POP3Client/README.OpenSource.md create mode 100644 POP3Client/README.md create mode 100644 POP3Client/TEST.md create mode 100644 SMTPClient/CHANGELOG.md create mode 100644 SMTPClient/LICENSE create mode 100644 SMTPClient/OAT.xml create mode 100644 SMTPClient/README.OpenSource create mode 100644 SMTPClient/README.md create mode 100644 SMTPClient/TEST.md diff --git a/FTPClient/CHANGELOG.md b/FTPClient/CHANGELOG.md new file mode 100644 index 0000000..3a14a3a --- /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 0000000..804e800 --- /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 0000000..546e4d4 --- /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 0000000..41d4789 --- /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 0000000..770c522 --- /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 4ded493..26ea5ee 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 4aa8040..cb2778e 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 2c008d5..2570f6d 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 f7232e4..6edc123 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/ohosTest/ets/MockFtpServer.ets b/FTPClient/entry/src/ohosTest/ets/MockFtpServer.ets index b4d656e..7777ecf 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 140ca1a..37ed8ef 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 e128b2d..ce7169e 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 d140b95..6978bb8 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 0705f62..02db7d2 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 548db5c..4b830e3 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 834df45..4157a6f 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 c1b4094..0df150a 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 66b46b8..e48bd4b 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 942957e..68bee7b 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 6c6b701..976f1cf 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 3b89321..cceb034 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 6ea8c84..d6b42b1 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 4e291d3..94b40a4 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 aab02bf..985e292 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 bd7bd56..694ab32 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/ohosTest/ets/test/Ability.test.ets b/IMAPClient/entry/src/ohosTest/ets/test/Ability.test.ets index 8abf7f2..ef5e74b 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 d3b6514..8b5acd4 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 3cc6ec0..1a89e92 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 0000000..e3f5c2f --- /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 0000000..5aabb26 --- /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 0000000..fb23c1b --- /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 0000000..e7f42d6 --- /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 0000000..4670fe4 --- /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 0000000..a465aff --- /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 6e2b921..5532745 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 a2e3286..887db5a 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'; diff --git a/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets b/POP3Client/entry/src/main/ets/pages/AutoLoginCommandPage.ets index 1232553..6a10b7c 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' diff --git a/POP3Client/entry/src/main/ets/pages/CommandPage.ets b/POP3Client/entry/src/main/ets/pages/CommandPage.ets index 48f658b..bd55690 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 7326672..665d259 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 84946f3..43c4ece 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/ohosTest/ets/test/Ability.test.ets b/POP3Client/entry/src/ohosTest/ets/test/Ability.test.ets index 50f4ed6..7b970af 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 500d462..ee82ae4 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 2b0c2a7..4173867 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 0705f62..02db7d2 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 548db5c..4b830e3 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 834df45..4157a6f 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 0000000..35240a7 --- /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 0000000..f98013c --- /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 0000000..c788bf3 --- /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 0000000..67c6ae1 --- /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 0000000..f4d8def --- /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 0000000..dc4a5d7 --- /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/entry/src/main/ets/entryability/EntryAbility.ts b/SMTPClient/entry/src/main/ets/entryability/EntryAbility.ts index 8a7aef0..6aee93d 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'; diff --git a/SMTPClient/entry/src/main/ets/pages/LoginPage.ets b/SMTPClient/entry/src/main/ets/pages/LoginPage.ets index 466bce7..c8dc2cc 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 a21068b..52df92f 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' diff --git a/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets b/SMTPClient/entry/src/ohosTest/ets/testability/TestAbility.ets index e3f6e91..e0bf140 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 1663665..ab6dda5 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 92a16d8..f6d93ba 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'; -- Gitee