thunderbird-account-qr-code 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +23 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Thunderbird account QR code
2
2
  [![codecov](https://codecov.io/gh/freaktechnik/thunderbird-account-qr-code/graph/badge.svg?token=HGWPlqqIdA)](https://codecov.io/gh/freaktechnik/thunderbird-account-qr-code)
3
3
 
4
- Thunderbird for Android allows importing accounts through a QR code. This allows easy transmission of account configuration details. The goal of this library is to help with generating such QR codes by formatting the information as required by the [format for Thunderbird for Android](https://github.com/thunderbird/thunderbird-android/blob/8c2c036d36344f56128fcad77a5f355336ad67cc/feature/migration/qrcode/qr-code-format.md).
4
+ Thunderbird for Android allows [importing accounts through a QR code](https://support.mozilla.org/kb/thunderbird-android-import#w_import-the-desktop-settings-into-thunderbird-for-android). This allows easy transmission of account configuration details. The goal of this library is to help with generating such QR codes by formatting the information as required by the [format for Thunderbird for Android](https://github.com/thunderbird/thunderbird-android/blob/8c2c036d36344f56128fcad77a5f355336ad67cc/feature/migration/qrcode/qr-code-format.md).
5
5
 
6
6
  It does, however, not include any actual QR generation capabilities, you can choose almost any library that can encode an arbitrary string as data. Note that you might have to appropriately encode the string first, so UTF-8 code points are properly transmitted.
7
7
 
@@ -43,7 +43,7 @@ const qrInput = encodeAccounts([ {
43
43
 
44
44
  ## Example usage
45
45
 
46
- You can find the example provided in the `exmample` directory hosted at https://lab.humanoids.be/thunderbird-account-qr-code/example.
46
+ You can find the example provided in the `example` directory hosted at https://lab.humanoids.be/thunderbird-account-qr-code/example.
47
47
 
48
48
  ## License
49
49
 
package/index.js CHANGED
@@ -113,10 +113,6 @@ function optionalArrayItems(condition, items) {
113
113
  return items;
114
114
  }
115
115
 
116
- function isEmptyValue(value) {
117
- return !value && (value === null || value === "");
118
- }
119
-
120
116
  /**
121
117
  * Build the IncomingServer element.
122
118
  *
@@ -124,6 +120,24 @@ function isEmptyValue(value) {
124
120
  * @returns {any[]}
125
121
  */
126
122
  function getIncomingServer(accountInfo) {
123
+ let { incomingAccountName } = accountInfo;
124
+ // If the account name is omitted, the email address of the first
125
+ // identity is used.
126
+ if(accountInfo.incomingAccountName === accountInfo.identityEmailAddress) {
127
+ incomingAccountName = "";
128
+ }
129
+ // null is treated the same as an empty string, and the empty string is
130
+ // shorter in JSON.
131
+ if(accountInfo.incomingAccountName === null) {
132
+ incomingAccountName = "";
133
+ }
134
+ // The account name and password section should be omitted
135
+ const shouldIncludeAccountNameAndPassword = accountInfo.incomingPassword || incomingAccountName;
136
+
137
+ // Make sure we have a valid empty value if we're providing a password.
138
+ if(incomingAccountName === undefined && shouldIncludeAccountNameAndPassword) {
139
+ incomingAccountName = "";
140
+ }
127
141
  return [
128
142
  accountInfo.incomingProtocol,
129
143
  accountInfo.incomingHostname,
@@ -131,8 +145,8 @@ function getIncomingServer(accountInfo) {
131
145
  accountInfo.incomingConnectionSecurity,
132
146
  accountInfo.incomingAuthenticationType,
133
147
  accountInfo.incomingUsername,
134
- ...optionalArrayItems(accountInfo.incomingAccountName || isEmptyValue(accountInfo.incomingAccountName), [
135
- accountInfo.incomingAccountName,
148
+ ...optionalArrayItems(shouldIncludeAccountNameAndPassword, [
149
+ incomingAccountName,
136
150
  ...optionalArrayItems(accountInfo.incomingPassword, [ accountInfo.incomingPassword ]),
137
151
  ]),
138
152
  ];
@@ -212,10 +226,10 @@ function getAccountArrays(accountInfo) {
212
226
  *
213
227
  * @param {AccountInfo[]} accountInfos
214
228
  * @param {number} [sequenceNumber=1] - The (1-based) position of this QR code
215
- * in a sequence of QR codes. When only transmitting a single account this can
216
- * be safely omitted.
229
+ * in a sequence of QR codes. When only transmitting a single account this can
230
+ * be safely omitted.
217
231
  * @param {number} [sequenceTotal=1] - The total QR codes in the sequence. When
218
- * only transmitting a single account this can be safely omitted.
232
+ * only transmitting a single account this can be safely omitted.
219
233
  * @returns {string}
220
234
  */
221
235
  /* eslint-enable no-secrets/no-secrets */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderbird-account-qr-code",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Encode E-Mail account info in a QR code for import in Thunderbird for Android\"",
5
5
  "main": "index.js",
6
6
  "type": "module",