iobroker.imap 0.2.2 → 0.3.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.
package/main.js CHANGED
@@ -13,7 +13,7 @@ const helper = require("./lib/helper");
13
13
  const tl = require("./lib/translator");
14
14
  const format = require("util").format;
15
15
  const { convert } = require("html-to-text");
16
- const imap_connect = require("./lib/Connection");
16
+ const imap_connect = require("imap-iobroker");
17
17
  const imap_event = require("./lib/imap_event");
18
18
  const FORBIDDEN_CHARS = /[üäöÜÄÖ$@߀*:.]|[^._\-/ :!#$%&()+=@^{}|~\p{Ll}\p{Lu}\p{Nd}]+/gu;
19
19
  const empty = {
@@ -73,6 +73,9 @@ class Imap extends utils.Adapter {
73
73
  this.updateseqno = imap_event.updateseqno;
74
74
  this.updatemail = imap_event.updatemail;
75
75
  this.change_events = imap_event.change_events;
76
+ this.addBox = imap_event.addBox;
77
+ this.deleteBox = imap_event.deleteBox;
78
+ this.rename = imap_event.rename;
76
79
  this.changeFolder = imap_event.changeFolder;
77
80
  this.custom_search = imap_event.custom_search;
78
81
  this.loadUnseenSeqno = imap_event.loadUnseenSeqno;
@@ -153,8 +156,8 @@ class Imap extends utils.Adapter {
153
156
  check_name[jsons.nodename] = jsons.nodename;
154
157
  }
155
158
  }
156
- devices["data"] = this.config.hosts;
157
- selectbox["states"] = {};
159
+ devices.data = this.config.hosts;
160
+ selectbox.states = {};
158
161
  await this.createCounter();
159
162
  for (const dev of devices.data) {
160
163
  if (dev.inbox == "") {
@@ -173,7 +176,7 @@ class Imap extends utils.Adapter {
173
176
  this.log_translator("info", "missing username");
174
177
  continue;
175
178
  } else {
176
- dev["username"] = dev.user;
179
+ dev.username = dev.user;
177
180
  dev.user = dev.user.replace(FORBIDDEN_CHARS, "_");
178
181
  }
179
182
  if (dev.password != "" && dev.password.includes("<LUCKY-ESA>")) {
@@ -185,19 +188,18 @@ class Imap extends utils.Adapter {
185
188
  this.log_translator("info", "Cannot found password", dev.user);
186
189
  continue;
187
190
  }
188
- } catch (e) {
191
+ } catch {
189
192
  this.log_translator("info", "decrypt pw", dev.user);
190
193
  continue;
191
194
  }
192
195
  } else if (dev.password == "") {
193
196
  this.log_translator("info", "missing password");
194
197
  continue;
198
+ } else if (dev.token == "") {
199
+ this.log_translator("info", "missing password");
200
+ continue;
195
201
  }
196
- //} else if (dev.token == "") {
197
- // this.log_translator("info", "missing password");
198
- // continue;
199
- //}
200
- dev.node_option = config_array.find((node) => node.nodename === dev.node_option);
202
+ dev.node_option = config_array.find(node => node.nodename === dev.node_option);
201
203
  if (
202
204
  dev.node_option &&
203
205
  dev.node_option.maxHtmlLengthToParse != null &&
@@ -207,8 +209,8 @@ class Imap extends utils.Adapter {
207
209
  }
208
210
  if (dev.node_option == -1) {
209
211
  dev.node_option = {};
210
- } else if (dev.node_option && dev.node_option["nodename"] != null) {
211
- delete dev.node_option["nodename"];
212
+ } else if (dev.node_option && dev.node_option.nodename != null) {
213
+ delete dev.node_option.nodename;
212
214
  } else {
213
215
  dev.node_option = {};
214
216
  }
@@ -216,8 +218,8 @@ class Imap extends utils.Adapter {
216
218
  dev.maxi_html = dev.maxi_html < 1 ? 1 : dev.maxi_html;
217
219
  dev.maxi = dev.maxi > 99 ? 99 : dev.maxi;
218
220
  dev.maxi = dev.maxi < 1 ? 1 : dev.maxi;
219
- dev["max"] = dev.maxi_html > dev.maxi ? dev.maxi_html : dev.maxi;
220
- dev["inbox_activ"] = dev.inbox;
221
+ dev.max = dev.maxi_html > dev.maxi ? dev.maxi_html : dev.maxi;
222
+ dev.inbox_activ = dev.inbox;
221
223
  this.clientsIDdelete.push(dev);
222
224
  if (!dev.activ) {
223
225
  await this.cleanupDatapoints(dev);
@@ -231,7 +233,7 @@ class Imap extends utils.Adapter {
231
233
  this.boxfolder[dev.user] = {};
232
234
  this.restartIMAPConnection[dev.user] = null;
233
235
  this.clientsRows[dev.user] = "";
234
- selectbox["states"][dev.user] = dev.user;
236
+ selectbox.states[dev.user] = dev.user;
235
237
  this.clients[dev.user] = null;
236
238
  this.clientsRaw[dev.user] = dev;
237
239
  this.all_seqno[dev.user] = [];
@@ -282,7 +284,7 @@ class Imap extends utils.Adapter {
282
284
  if (dev.user != null && dev.user != "") {
283
285
  const isDP = await this.getStateAsync(`${dev.user}.online`);
284
286
  if (isDP != null) {
285
- await this.setStateAsync(`${dev.user}.online`, {
287
+ await this.setState(`${dev.user}.online`, {
286
288
  val: false,
287
289
  ack: true,
288
290
  });
@@ -306,7 +308,7 @@ class Imap extends utils.Adapter {
306
308
  }
307
309
 
308
310
  /**
309
- *
311
+ * connectionCheck
310
312
  */
311
313
  async connectionCheck() {
312
314
  for (const dev of this.clientsID) {
@@ -403,14 +405,14 @@ class Imap extends utils.Adapter {
403
405
  }
404
406
 
405
407
  /**
406
- *
408
+ * checkDeviceFolder
407
409
  */
408
410
  async checkDeviceFolder() {
409
411
  try {
410
412
  const devices = await this.getDevicesAsync();
411
413
  for (const element of devices) {
412
414
  const id = element["_id"].split(".").pop();
413
- const isfind = this.clientsIDdelete.find((mes) => mes.user === id);
415
+ const isfind = this.clientsIDdelete.find(mes => mes.user === id);
414
416
  if (isfind) {
415
417
  this.log_translator("debug", "Found data point", element["_id"]);
416
418
  } else {
@@ -424,7 +426,7 @@ class Imap extends utils.Adapter {
424
426
  }
425
427
 
426
428
  /**
427
- *
429
+ * configcheck
428
430
  */
429
431
  async configcheck() {
430
432
  try {
@@ -461,17 +463,16 @@ class Imap extends utils.Adapter {
461
463
  return true;
462
464
  }
463
465
  return false;
464
- } catch (error) {
465
- this.log_translator("error", "try", `configcheck: ${error}`);
466
+ } catch (e) {
467
+ this.log_translator("error", "try", `configcheck: ${e}`);
466
468
  }
467
469
  }
468
470
 
469
- /**
470
471
  async loadToken(dev) {
471
472
  const search_token = {};
472
473
  search_token["token"] = this.config.oauth_token;
473
474
  let msalConfig;
474
- const isfind = search_token["token"].find((tok) => tok.name === dev.token);
475
+ const isfind = search_token["token"].find(tok => tok.name === dev.token);
475
476
  if (
476
477
  isfind != null &&
477
478
  isfind.name != null &&
@@ -490,7 +491,7 @@ class Imap extends utils.Adapter {
490
491
  this.log_translator("info", "Security-ID", isfind.user);
491
492
  dev.token = null;
492
493
  }
493
- } catch (e) {
494
+ } catch {
494
495
  return (dev.token = null);
495
496
  }
496
497
  } else {
@@ -499,28 +500,37 @@ class Imap extends utils.Adapter {
499
500
  msalConfig = {
500
501
  auth: {
501
502
  clientId: isfind.clientid,
502
- authority: `https://login.microsoftonline.com/${isfind.pathid}/`,
503
+ authority: `https://login.microsoftonline.com/${isfind.pathid}`,
503
504
  clientSecret: isfind.secureid,
504
505
  },
505
506
  };
506
- const cca = new msal.ConfidentialClientApplication(msalConfig);
507
+ const cca = msal ? new msal.ConfidentialClientApplication(msalConfig) : null;
507
508
  const tokenRequest = {
508
509
  scopes: ["https://graph.microsoft.com/.default"],
509
510
  };
510
- const accessT = await cca.acquireTokenByClientCredential(tokenRequest);
511
+ let accessT;
512
+ if (cca) {
513
+ try {
514
+ accessT = await cca.acquireTokenByClientCredential(tokenRequest);
515
+ } catch (e) {
516
+ this.log.error(`TokenCredential error: ${e}`);
517
+ dev.token = null;
518
+ }
519
+ } else {
520
+ this.log.debug(`Credential error!!`);
521
+ dev.token = null;
522
+ }
511
523
  if (accessT && accessT.accessToken) {
512
524
  dev.token = Buffer.from(
513
525
  [`user=${dev.user}`, `auth=Bearer ${accessT.accessToken}`, "", ""].join("\x01"),
514
526
  "utf-8",
515
527
  ).toString("base64");
516
528
  return dev.token;
517
- } else {
518
- dev.token = null;
519
529
  }
530
+ dev.token = null;
520
531
  }
521
532
  dev.token = null;
522
533
  }
523
- */
524
534
 
525
535
  /**
526
536
  * @param {object} dev
@@ -533,7 +543,6 @@ class Imap extends utils.Adapter {
533
543
  }
534
544
  this.restartIMAPConnection[dev.user] && this.clearTimeout(this.restartIMAPConnection[dev.user]);
535
545
  this.restartIMAPConnection[dev.user] = null;
536
- /**
537
546
  if (
538
547
  dev.token &&
539
548
  dev.token != "" &&
@@ -555,14 +564,13 @@ class Imap extends utils.Adapter {
555
564
  } else {
556
565
  dev.token = null;
557
566
  }
558
- */
559
567
  try {
560
568
  if (typeof dev.flag === "object") {
561
569
  this.clientsRaw[dev.user].flag = JSON.parse(JSON.stringify(dev.flag));
562
570
  } else {
563
571
  this.clientsRaw[dev.user].flag = JSON.parse(dev.flag);
564
572
  }
565
- } catch (e) {
573
+ } catch {
566
574
  this.clientsRaw[dev.user].flag = ["ALL"];
567
575
  }
568
576
  //this.dir[dev.user] = `${__dirname}/lib/attachment`;
@@ -573,7 +581,7 @@ class Imap extends utils.Adapter {
573
581
  } else {
574
582
  tlsoption = JSON.parse(dev.tlsoption);
575
583
  }
576
- } catch (e) {
584
+ } catch {
577
585
  this.log_translator("warn", "TLSOPTION", dev.user);
578
586
  }
579
587
  this.clientsRaw[dev.user].inbox_activ = dev.inbox;
@@ -637,7 +645,7 @@ class Imap extends utils.Adapter {
637
645
  this.save_json[clientID] = this.save_json[clientID].sort((a, b) => b.date - a.date);
638
646
  this.updateseqno(clientID, del_seqno["seqno"], false);
639
647
  } else {
640
- const merge = this.save_json[clientID].findIndex((merge) => merge.seqno === seqno);
648
+ const merge = this.save_json[clientID].findIndex(merge => merge.seqno === seqno);
641
649
  if (merge != -1) {
642
650
  this.save_json[clientID][merge] = mail;
643
651
  }
@@ -683,7 +691,7 @@ class Imap extends utils.Adapter {
683
691
  }
684
692
 
685
693
  /**
686
- *
694
+ * checksupport
687
695
  */
688
696
  async checksupport() {
689
697
  await this.sleep(5000);
@@ -717,7 +725,9 @@ class Imap extends utils.Adapter {
717
725
  try {
718
726
  for (const capability of capabilitys) {
719
727
  const sorts = await this.clients[dev].serverSupports(capability);
720
- if (capability === "QUOTA") quota = sorts;
728
+ if (capability === "QUOTA") {
729
+ quota = sorts;
730
+ }
721
731
  const dp_capability = capability.replace(/[=|-|+]/g, "_");
722
732
  common = {
723
733
  type: "boolean",
@@ -729,7 +739,7 @@ class Imap extends utils.Adapter {
729
739
  def: false,
730
740
  };
731
741
  await this.createDataPoint(`${dev}.infos.${dp_capability.toLowerCase()}`, common, "state");
732
- await this.setStateAsync(`${dev}.infos.${dp_capability.toLowerCase()}`, {
742
+ await this.setState(`${dev}.infos.${dp_capability.toLowerCase()}`, {
733
743
  val: sorts,
734
744
  ack: true,
735
745
  });
@@ -746,7 +756,7 @@ class Imap extends utils.Adapter {
746
756
  def: "",
747
757
  };
748
758
  await this.createDataPoint(`${dev}.infos.all_capability`, common, "state");
749
- await this.setStateAsync(`${dev}.infos.all_capability`, {
759
+ await this.setState(`${dev}.infos.all_capability`, {
750
760
  val: JSON.stringify(caps),
751
761
  ack: true,
752
762
  });
@@ -821,15 +831,15 @@ class Imap extends utils.Adapter {
821
831
  */
822
832
  async setUpdate(clientID, info, trans) {
823
833
  const activity = this.helper_translator(trans) != null ? this.helper_translator(trans) : "";
824
- await this.setStateAsync(`${clientID}.last_activity`, {
834
+ await this.setState(`${clientID}.last_activity`, {
825
835
  val: activity,
826
836
  ack: true,
827
837
  });
828
- await this.setStateAsync(`${clientID}.last_activity_json`, {
838
+ await this.setState(`${clientID}.last_activity_json`, {
829
839
  val: typeof info === "object" ? JSON.stringify(info) : JSON.stringify({ seqno: "0" }),
830
840
  ack: true,
831
841
  });
832
- await this.setStateAsync(`${clientID}.last_activity_timestamp`, {
842
+ await this.setState(`${clientID}.last_activity_timestamp`, {
833
843
  val: Date.now(),
834
844
  ack: true,
835
845
  });
@@ -845,25 +855,25 @@ class Imap extends utils.Adapter {
845
855
  */
846
856
  async setStatesValue(mail, seqno, clientID, count, attrs, info) {
847
857
  try {
848
- const id = `${clientID}.email.email_${("0" + count).slice(-2)}`;
849
- await this.setStateAsync(`${id}.subject`, {
858
+ const id = `${clientID}.email.email_${`0${count}`.slice(-2)}`;
859
+ await this.setState(`${id}.subject`, {
850
860
  val: mail.subject != null ? mail.subject : this.helper_translator("Unknown"),
851
861
  ack: true,
852
862
  });
853
863
  //const receive_date = mail.date.toISOString().replace("T", " ").replace(/\..+/, "");
854
- await this.setStateAsync(`${id}.receive`, {
864
+ await this.setState(`${id}.receive`, {
855
865
  val: mail.date != null ? mail.date.toString() : this.helper_translator("Unknown"),
856
866
  ack: true,
857
867
  });
858
- await this.setStateAsync(`${id}.content`, {
868
+ await this.setState(`${id}.content`, {
859
869
  val: mail.html != null && mail.html ? mail.html : this.helper_translator("Unknown"),
860
870
  ack: true,
861
871
  });
862
- await this.setStateAsync(`${id}.text`, {
872
+ await this.setState(`${id}.text`, {
863
873
  val: mail.text != null ? mail.text : this.helper_translator("Unknown"),
864
874
  ack: true,
865
875
  });
866
- await this.setStateAsync(`${id}.texthtml`, {
876
+ await this.setState(`${id}.texthtml`, {
867
877
  val: mail.textAsHtml != null ? mail.textAsHtml : this.helper_translator("Unknown"),
868
878
  ack: true,
869
879
  });
@@ -875,7 +885,7 @@ class Imap extends utils.Adapter {
875
885
  }
876
886
  }
877
887
  }
878
- await this.setStateAsync(`${id}.to`, {
888
+ await this.setState(`${id}.to`, {
879
889
  val: JSON.stringify(add),
880
890
  ack: true,
881
891
  });
@@ -887,31 +897,31 @@ class Imap extends utils.Adapter {
887
897
  }
888
898
  }
889
899
  }
890
- await this.setStateAsync(`${id}.from`, {
900
+ await this.setState(`${id}.from`, {
891
901
  val: JSON.stringify(add),
892
902
  ack: true,
893
903
  });
894
- await this.setStateAsync(`${id}.flag`, {
904
+ await this.setState(`${id}.flag`, {
895
905
  val: attrs.flags != null ? JSON.stringify(attrs.flags) : this.helper_translator("Unknown"),
896
906
  ack: true,
897
907
  });
898
- await this.setStateAsync(`${id}.uid`, {
908
+ await this.setState(`${id}.uid`, {
899
909
  val: attrs.uid != null ? attrs.uid : 0,
900
910
  ack: true,
901
911
  });
902
- await this.setStateAsync(`${id}.seq`, {
912
+ await this.setState(`${id}.seq`, {
903
913
  val: seqno != null ? seqno : 0,
904
914
  ack: true,
905
915
  });
906
- await this.setStateAsync(`${id}.size`, {
916
+ await this.setState(`${id}.size`, {
907
917
  val: info.size != null ? info.size : 0,
908
918
  ack: true,
909
919
  });
910
- await this.setStateAsync(`${id}.attach`, {
920
+ await this.setState(`${id}.attach`, {
911
921
  val: mail.attachments != null ? mail.attachments : 0,
912
922
  ack: true,
913
923
  });
914
- await this.setStateAsync(`${id}.attach_json`, {
924
+ await this.setState(`${id}.attach_json`, {
915
925
  val: mail.attachments_info != null ? JSON.stringify(mail.attachments_info) : JSON.stringify([]),
916
926
  ack: true,
917
927
  });
@@ -929,14 +939,11 @@ class Imap extends utils.Adapter {
929
939
  }
930
940
  this.double_call[obj._id] = true;
931
941
  this.log_translator("debug", "Message", JSON.stringify(obj));
932
- let adapterconfigs = {};
933
942
  let _obj = {};
934
943
  try {
935
- // @ts-ignore
936
- adapterconfigs = this.adapterConfig;
937
944
  _obj = JSON.parse(JSON.stringify(obj));
938
- } catch (error) {
939
- this.log_translator("error", "catch", `onMessage: ${error}`);
945
+ } catch (e) {
946
+ this.log_translator("error", "catch", `onMessage: ${e}`);
940
947
  this.sendTo(obj.from, obj.command, [], obj.callback);
941
948
  delete this.double_call[obj._id];
942
949
  return;
@@ -949,8 +956,9 @@ class Imap extends utils.Adapter {
949
956
  const icons = [];
950
957
  if (_obj && _obj.message && _obj.message.icon && _obj.message.icon.icons) {
951
958
  icon_array = _obj.message.icon.icons;
952
- } else if (adapterconfigs && adapterconfigs.native && adapterconfigs.native.icons) {
953
- icon_array = adapterconfigs.native.icons;
959
+ } else {
960
+ this.sendTo(obj.from, obj.command, [], obj.callback);
961
+ return;
954
962
  }
955
963
  if (icon_array && Object.keys(icon_array).length > 0) {
956
964
  for (const icon of icon_array) {
@@ -962,9 +970,9 @@ class Imap extends utils.Adapter {
962
970
  } else {
963
971
  this.sendTo(obj.from, obj.command, [], obj.callback);
964
972
  }
965
- } catch (error) {
973
+ } catch (e) {
966
974
  delete this.double_call[obj._id];
967
- this.log_translator("error", "catch", `onMessage: ${error}`);
975
+ this.log_translator("error", "catch", `onMessage: ${e}`);
968
976
  this.sendTo(obj.from, obj.command, [], obj.callback);
969
977
  }
970
978
  }
@@ -977,8 +985,9 @@ class Imap extends utils.Adapter {
977
985
  const tokens = [];
978
986
  if (_obj && _obj.message && _obj.message.token && _obj.message.token.tokens) {
979
987
  token_array = _obj.message.token.tokens;
980
- } else if (adapterconfigs && adapterconfigs.native && adapterconfigs.native.oauth_token) {
981
- token_array = adapterconfigs.native.oauth_token;
988
+ } else {
989
+ this.sendTo(obj.from, obj.command, [], obj.callback);
990
+ return;
982
991
  }
983
992
  if (token_array && Object.keys(token_array).length > 0) {
984
993
  for (const token of token_array) {
@@ -992,9 +1001,9 @@ class Imap extends utils.Adapter {
992
1001
  } else {
993
1002
  this.sendTo(obj.from, obj.command, [], obj.callback);
994
1003
  }
995
- } catch (error) {
1004
+ } catch (e) {
996
1005
  delete this.double_call[obj._id];
997
- this.log_translator("error", "catch", `onMessage: ${error}`);
1006
+ this.log_translator("error", "catch", `onMessage: ${e}`);
998
1007
  this.sendTo(obj.from, obj.command, [], obj.callback);
999
1008
  }
1000
1009
  }
@@ -1007,12 +1016,9 @@ class Imap extends utils.Adapter {
1007
1016
  const mailers = [];
1008
1017
  if (_obj && _obj.message && _obj.message.node_option && _obj.message.node_option.node_options) {
1009
1018
  mailer_array = _obj.message.node_option.node_options;
1010
- } else if (
1011
- adapterconfigs &&
1012
- adapterconfigs.native &&
1013
- adapterconfigs.native.nodemailer_options
1014
- ) {
1015
- mailer_array = adapterconfigs.native.nodemailer_options;
1019
+ } else {
1020
+ this.sendTo(obj.from, obj.command, [], obj.callback);
1021
+ return;
1016
1022
  }
1017
1023
  if (mailer_array && Object.keys(mailer_array).length > 0) {
1018
1024
  for (const mailer of mailer_array) {
@@ -1026,9 +1032,9 @@ class Imap extends utils.Adapter {
1026
1032
  } else {
1027
1033
  this.sendTo(obj.from, obj.command, [], obj.callback);
1028
1034
  }
1029
- } catch (error) {
1035
+ } catch (e) {
1030
1036
  delete this.double_call[obj._id];
1031
- this.log_translator("error", "catch", `onMessage: ${error}`);
1037
+ this.log_translator("error", "catch", `onMessage: ${e}`);
1032
1038
  this.sendTo(obj.from, obj.command, [], obj.callback);
1033
1039
  }
1034
1040
  }
@@ -1037,31 +1043,31 @@ class Imap extends utils.Adapter {
1037
1043
  case "getBlockly":
1038
1044
  if (
1039
1045
  obj.message &&
1040
- obj.message["search"] != "" &&
1041
- obj.message["device"] != "" &&
1042
- obj.message["max"] > 0 &&
1043
- obj.message["max"] < 100
1046
+ obj.message.search != "" &&
1047
+ obj.message.device != "" &&
1048
+ obj.message.max > 0 &&
1049
+ obj.message.max < 100
1044
1050
  ) {
1045
- if (obj.message["device"] === "all") {
1051
+ if (obj.message.device === "all") {
1046
1052
  for (const dev in this.clientsRaw) {
1047
1053
  const userdev = this.clientsRaw[dev];
1048
1054
  if (userdev.activ) {
1049
- this.setStateSearch(userdev.user, obj.message["search"], obj.message["max"]);
1055
+ this.setStateSearch(userdev.user, obj.message.search, obj.message.max);
1050
1056
  }
1051
1057
  }
1052
1058
  } else {
1053
- const user = obj.message["device"].replace(FORBIDDEN_CHARS, "_");
1059
+ const user = obj.message.device.replace(FORBIDDEN_CHARS, "_");
1054
1060
  if (this.clientsRaw[user]) {
1055
1061
  if (this.clientsRaw[user].activ) {
1056
- this.setStateSearch(user, obj.message["search"], obj.message["max"]);
1062
+ this.setStateSearch(user, obj.message.search, obj.message.max);
1057
1063
  } else {
1058
- this.log_translator("info", "IMAP disabled", `${user} - ${obj.message["device"]}`);
1064
+ this.log_translator("info", "IMAP disabled", `${user} - ${obj.message.device}`);
1059
1065
  }
1060
1066
  } else {
1061
- this.log_translator("info", "not found imap", `${user} - ${obj.message["device"]}`);
1067
+ this.log_translator("info", "not found imap", `${user} - ${obj.message.device}`);
1062
1068
  }
1063
1069
  }
1064
- } else if (obj.message && obj.message["max"] < 1 && obj.message["max"] > 100) {
1070
+ } else if (obj.message && obj.message.max < 1 && obj.message.max > 100) {
1065
1071
  this.log_translator("info", "max_mail");
1066
1072
  } else {
1067
1073
  this.sendTo(obj.from, obj.command, [], obj.callback);
@@ -1071,18 +1077,18 @@ class Imap extends utils.Adapter {
1071
1077
  if (obj.callback) {
1072
1078
  if (
1073
1079
  obj.message &&
1074
- obj.message["search"] != "" &&
1075
- obj.message["name"] != "" &&
1076
- obj.message["bodie"] != "" &&
1077
- obj.message["parse"] != null &&
1078
- obj.message["max"] > 0 &&
1079
- obj.message["max"] < 100
1080
+ obj.message.search != "" &&
1081
+ obj.message.name != "" &&
1082
+ obj.message.bodie != "" &&
1083
+ obj.message.parse != null &&
1084
+ obj.message.max > 0 &&
1085
+ obj.message.max < 100
1080
1086
  ) {
1081
- if (obj.message["name"] !== "all") {
1082
- const user = obj.message["name"].replace(FORBIDDEN_CHARS, "_");
1087
+ if (obj.message.name !== "all") {
1088
+ const user = obj.message.name.replace(FORBIDDEN_CHARS, "_");
1083
1089
  try {
1084
1090
  this.custom_search(user, _obj);
1085
- } catch (e) {
1091
+ } catch {
1086
1092
  this.sendTo(obj.from, obj.command, [], obj.callback);
1087
1093
  }
1088
1094
  } else {
@@ -1090,7 +1096,7 @@ class Imap extends utils.Adapter {
1090
1096
  this.sendTo(obj.from, obj.command, [], obj.callback);
1091
1097
  }
1092
1098
  }
1093
- } else if (obj.message && obj.message["max"] < 1 && obj.message["max"] > 100) {
1099
+ } else if (obj.message && obj.message.max < 1 && obj.message.max > 100) {
1094
1100
  this.log_translator("info", "max_mail");
1095
1101
  } else {
1096
1102
  this.sendTo(obj.from, obj.command, [], obj.callback);
@@ -1098,10 +1104,10 @@ class Imap extends utils.Adapter {
1098
1104
  break;
1099
1105
  case "getIMAPData":
1100
1106
  if (obj.callback) {
1101
- if (obj.message && obj.message["name"] != "" && obj.message["value"] != "") {
1102
- if (obj.message["name"] !== "all") {
1103
- const user = obj.message["name"].replace(FORBIDDEN_CHARS, "_");
1104
- if (obj.message["value"] === "data") {
1107
+ if (obj.message && obj.message.name != "" && obj.message.value != "") {
1108
+ if (obj.message.name !== "all") {
1109
+ const user = obj.message.name.replace(FORBIDDEN_CHARS, "_");
1110
+ if (obj.message.value === "data") {
1105
1111
  this.sendTo(obj.from, obj.command, this.save_json[user], obj.callback);
1106
1112
  } else {
1107
1113
  this.sendTo(obj.from, obj.command, this.save_seqno[user], obj.callback);
@@ -1116,32 +1122,26 @@ class Imap extends utils.Adapter {
1116
1122
  case "getFlags":
1117
1123
  if (
1118
1124
  obj.message &&
1119
- obj.message["flag"] != "" &&
1120
- obj.message["uid"] > 0 &&
1121
- obj.message["name"] != "" &&
1122
- obj.message["flagtype"] != "" &&
1123
- obj.message["name"] !== "all"
1125
+ obj.message.flag != "" &&
1126
+ obj.message.uid > 0 &&
1127
+ obj.message.name != "" &&
1128
+ obj.message.flagtype != "" &&
1129
+ obj.message.name !== "all"
1124
1130
  ) {
1125
- const user = obj.message["name"].replace(FORBIDDEN_CHARS, "_");
1126
- const check_flag = obj.message["flag"];
1127
- this.log_translator(
1128
- "info",
1129
- "Set Flags",
1130
- obj.message["flag"],
1131
- obj.message["uid"],
1132
- obj.message["flagtype"],
1133
- );
1131
+ const user = obj.message.name.replace(FORBIDDEN_CHARS, "_");
1132
+ const check_flag = obj.message.flag;
1133
+ this.log_translator("info", "Set Flags", obj.message.flag, obj.message.uid, obj.message.flagtype);
1134
1134
  const flags = [];
1135
1135
  const types = obj.message["flagtype"].replace(/ /g, "").split(",");
1136
1136
  for (const flag of types) {
1137
1137
  if (check_flag == "setFlags" || check_flag == "addFlags" || check_flag == "delFlags") {
1138
- flags.push("\\" + flag);
1138
+ flags.push(`\\${flag}`);
1139
1139
  } else {
1140
1140
  flags.push(flag);
1141
1141
  }
1142
1142
  }
1143
1143
  if (typeof this.clients[user] === "object") {
1144
- this.change_events(user, obj.message["flag"], obj.message["uid"], flags);
1144
+ this.change_events(user, obj.message.flag, obj.message.uid, flags);
1145
1145
  }
1146
1146
  }
1147
1147
  break;
@@ -1157,15 +1157,15 @@ class Imap extends utils.Adapter {
1157
1157
  * @param {number} max
1158
1158
  */
1159
1159
  async setStateSearch(id, criteria, max) {
1160
- await this.setStateAsync(`${id}.remote.criteria`, {
1160
+ await this.setState(`${id}.remote.criteria`, {
1161
1161
  val: criteria,
1162
1162
  ack: true,
1163
1163
  });
1164
- await this.setStateAsync(`${id}.remote.show_mails`, {
1164
+ await this.setState(`${id}.remote.show_mails`, {
1165
1165
  val: max,
1166
1166
  ack: true,
1167
1167
  });
1168
- await this.setStateAsync(`${id}.remote.search_start`, {
1168
+ await this.setState(`${id}.remote.search_start`, {
1169
1169
  val: true,
1170
1170
  ack: false,
1171
1171
  });
@@ -1175,7 +1175,7 @@ class Imap extends utils.Adapter {
1175
1175
  * @param {number} ms
1176
1176
  */
1177
1177
  sleep(ms) {
1178
- return new Promise((resolve) => {
1178
+ return new Promise(resolve => {
1179
1179
  this.sleepTimer = this.setTimeout(() => {
1180
1180
  resolve(true);
1181
1181
  }, ms);
@@ -1184,6 +1184,7 @@ class Imap extends utils.Adapter {
1184
1184
 
1185
1185
  /**
1186
1186
  * Is called when adapter shuts down - callback has to be called under any circumstances!
1187
+ *
1187
1188
  * @param {() => void} callback
1188
1189
  */
1189
1190
  onUnload(callback) {
@@ -1205,6 +1206,7 @@ class Imap extends utils.Adapter {
1205
1206
  this.setState("info.connection", false, true);
1206
1207
  callback();
1207
1208
  } catch (e) {
1209
+ this.log.error(`onunload - ${e}`);
1208
1210
  callback();
1209
1211
  }
1210
1212
  }
@@ -1224,7 +1226,7 @@ class Imap extends utils.Adapter {
1224
1226
  } else {
1225
1227
  history_value = [];
1226
1228
  }
1227
- } catch (e) {
1229
+ } catch {
1228
1230
  history_value = [];
1229
1231
  }
1230
1232
  if (Object.keys(history_value).length > limited_history) {
@@ -1244,8 +1246,7 @@ class Imap extends utils.Adapter {
1244
1246
  this.setState("online_history", JSON.stringify(history_value), true);
1245
1247
  }
1246
1248
  /**
1247
- * Is called if a subscribed state changes
1248
- * @param {string} id
1249
+ * @param {string} id Is called if a subscribed state changes
1249
1250
  * @param {ioBroker.State | null | undefined} state
1250
1251
  */
1251
1252
  async onStateChange(id, state) {
@@ -1300,6 +1301,24 @@ class Imap extends utils.Adapter {
1300
1301
  this.setAckFlag(id);
1301
1302
  return;
1302
1303
  }
1304
+ if (command === "mailbox_folder_create") {
1305
+ const val = typeof state.val === "string" ? state.val : JSON.stringify(state.val);
1306
+ this.addBox(clientID, val);
1307
+ this.setAckFlag(id, { val: "" });
1308
+ return;
1309
+ }
1310
+ if (command === "mailbox_folder_delete") {
1311
+ const val = typeof state.val === "string" ? state.val : JSON.stringify(state.val);
1312
+ this.deleteBox(clientID, val);
1313
+ this.setAckFlag(id, { val: "" });
1314
+ return;
1315
+ }
1316
+ if (command === "mailbox_folder_change_name") {
1317
+ const val = typeof state.val === "string" ? JSON.parse(state.val) : [];
1318
+ this.rename(clientID, val[0], val[1]);
1319
+ this.setAckFlag(id, { val: JSON.stringify(["oldname", "newname"]) });
1320
+ return;
1321
+ }
1303
1322
  if (command === "apply_move" && state.val) {
1304
1323
  this.applyCopyMove("move", clientID);
1305
1324
  this.setAckFlag(id, { val: false });
@@ -1397,7 +1416,9 @@ class Imap extends utils.Adapter {
1397
1416
  * @param {ioBroker.State | null | undefined} state
1398
1417
  */
1399
1418
  async setJson_table(state) {
1400
- if (state == null) return;
1419
+ if (state == null) {
1420
+ return;
1421
+ }
1401
1422
  const jsons = await this.getStateAsync(`${state.val}.json`);
1402
1423
  if (jsons && jsons.val) {
1403
1424
  this.setState(`json_table`, {
@@ -1505,7 +1526,9 @@ class Imap extends utils.Adapter {
1505
1526
  log_translator(level, text, merge_1, merge_2, merge_3) {
1506
1527
  try {
1507
1528
  let loglevel = true;
1508
- if (this.loglevel !== "debug" && level === "debug") loglevel = false;
1529
+ if (this.loglevel !== "debug" && level === "debug") {
1530
+ loglevel = false;
1531
+ }
1509
1532
  if (loglevel) {
1510
1533
  if (tl.trans[text] != null) {
1511
1534
  if (merge_3) {
@@ -1538,12 +1561,10 @@ class Imap extends utils.Adapter {
1538
1561
  return format(tl.trans[text][this.lang], merge, merge_1);
1539
1562
  } else if (merge) {
1540
1563
  return format(tl.trans[text][this.lang], merge);
1541
- } else {
1542
- return tl.trans[text][this.lang];
1543
1564
  }
1544
- } else {
1545
- return tl.trans["Unknown"][this.lang];
1565
+ return tl.trans[text][this.lang];
1546
1566
  }
1567
+ return tl.trans["Unknown"][this.lang];
1547
1568
  } catch (e) {
1548
1569
  this.log.error(`try helper_translator: ${e} - ${text}`);
1549
1570
  }
@@ -1563,8 +1584,8 @@ class Imap extends utils.Adapter {
1563
1584
  this.clientsRows[clientID] = "";
1564
1585
  }
1565
1586
  const id = this.clientsHTML[clientID];
1566
- const isEven = count % 2 != 0 ? id["mails_even_color"] : id["mails_odd_color"];
1567
- const isToday = (someDate) => {
1587
+ const isEven = count % 2 != 0 ? id.mails_even_color : id.mails_odd_color;
1588
+ const isToday = someDate => {
1568
1589
  const today = new Date();
1569
1590
  return (
1570
1591
  someDate.getDate() == today.getDate() &&
@@ -1580,9 +1601,9 @@ class Imap extends utils.Adapter {
1580
1601
  let flags_add = "";
1581
1602
  let flags_del = "";
1582
1603
  if (isToday(new Date(mail.date))) {
1583
- days = count % 2 != 0 ? id["mails_today_color"] : id["mails_today_color_odd"];
1604
+ days = count % 2 != 0 ? id.mails_today_color : id.mails_today_color_odd;
1584
1605
  } else {
1585
- days = count % 2 != 0 ? id["mails_nextday_color_even"] : id["mails_nextday_color_odd"];
1606
+ days = count % 2 != 0 ? id.mails_nextday_color_even : id.mails_nextday_color_odd;
1586
1607
  }
1587
1608
  const weight = attrs && attrs.flags != "" ? "normal" : "bold";
1588
1609
  let from = this.helper_translator("Unknown");
@@ -1602,43 +1623,43 @@ class Imap extends utils.Adapter {
1602
1623
  const org_subject = mail.subject;
1603
1624
  let subject = mail.subject;
1604
1625
  let content = mail.text != null ? mail.text : convert(mail.html);
1605
- if (id["choose_content"] == "html") {
1626
+ if (id.choose_content == "html") {
1606
1627
  content = mail.html != null ? mail.html : "";
1607
- } else if (id["choose_content"] == "text") {
1628
+ } else if (id.choose_content == "text") {
1608
1629
  content = mail.text != null ? mail.text : convert(mail.html);
1609
- } else if (id["choose_content"] == "textAsHtml") {
1630
+ } else if (id.choose_content == "textAsHtml") {
1610
1631
  content = mail.textAsHtml != null ? mail.textAsHtml : mail.text;
1611
- } else if (id["choose_content"] == "html_convert") {
1632
+ } else if (id.choose_content == "html_convert") {
1612
1633
  content = mail.html != null ? convert(mail.html) : mail.text;
1613
- } else if (id["choose_content"] == "textAsHtml_convert") {
1634
+ } else if (id.choose_content == "textAsHtml_convert") {
1614
1635
  content = mail.textAsHtml != null ? convert(mail.textAsHtml) : mail.text;
1615
1636
  }
1616
1637
  let org_content = content;
1617
1638
  if (org_content != null && org_content != "") {
1618
1639
  org_content = convert(org_content).replace(/["]+|[']+/g, "");
1619
1640
  }
1620
- if (mail.subject && mail.subject.toString().length > id["short_subject"] && id["short_subject"] > 0) {
1621
- subject = mail.subject.substring(0, id["short_subject"]);
1641
+ if (mail.subject && mail.subject.toString().length > id.short_subject && id.short_subject > 0) {
1642
+ subject = mail.subject.substring(0, id.short_subject);
1622
1643
  }
1623
- if (content && content.toString().length > id["short_content"] && id["short_content"] > 0) {
1624
- content = content.substring(0, id["short_content"]);
1644
+ if (content && content.toString().length > id.short_content && id.short_content > 0) {
1645
+ content = content.substring(0, id.short_content);
1625
1646
  }
1626
1647
  attrs.flags = attrs && attrs.flags != "" ? attrs.flags.toString().replace(/\\/g, "") : "unseen";
1627
1648
  action = `<option value="" selected="selected"></option>`;
1628
1649
  for (const inbox of this.boxfolder[clientID]) {
1629
1650
  if (inbox != this.clientsRaw[clientID].inbox_activ) {
1630
- action_copy += `<option value="copy<L>${attrs.uid}<L>${inbox}">${id["text_select_copy"]}${inbox}</option>`;
1631
- action += `<option value="move<L>${attrs.uid}<L>${inbox}">${id["text_select_move"]}${inbox}</option>`;
1651
+ action_copy += `<option value="copy<L>${attrs.uid}<L>${inbox}">${id.text_select_copy}${inbox}</option>`;
1652
+ action += `<option value="move<L>${attrs.uid}<L>${inbox}">${id.text_select_move}${inbox}</option>`;
1632
1653
  }
1633
1654
  }
1634
1655
  action += action_copy;
1635
1656
  flags = `<option value="" selected="selected"></option>`;
1636
1657
  for (const key of all_flags) {
1637
1658
  if (attrs.flags.indexOf(key) !== -1) {
1638
- flags_del += `<option value="delFlags<L>${attrs.uid}<L>${key}">${id["text_select_delflag"]}${key}</option>`;
1659
+ flags_del += `<option value="delFlags<L>${attrs.uid}<L>${key}">${id.text_select_delflag}${key}</option>`;
1639
1660
  } else {
1640
- flags += `<option value="setFlags<L>${attrs.uid}<L>${key}">${id["text_select_setflag"]}${key}</option>`;
1641
- flags_add += `<option value="addFlags<L>${attrs.uid}<L>${key}">${id["text_select_addflag"]}${key}</option>`;
1661
+ flags += `<option value="setFlags<L>${attrs.uid}<L>${key}">${id.text_select_setflag}${key}</option>`;
1662
+ flags_add += `<option value="addFlags<L>${attrs.uid}<L>${key}">${id.text_select_addflag}${key}</option>`;
1642
1663
  }
1643
1664
  }
1644
1665
  flags += flags_add;
@@ -1647,20 +1668,20 @@ class Imap extends utils.Adapter {
1647
1668
  <tr style="background-color:${isEven};
1648
1669
  color:${days};
1649
1670
  font-weight:${weight};
1650
- font-size:${id["header_font_size"]}px;">
1651
- <td style="text-align:${id["headline_align_column_1"]}">${count}</td>
1652
- <td title="${org_from}" style="text-align:${id["headline_align_column_2"]}">${from}</td>
1653
- <td title="${org_subject}" style="text-align:${id["headline_align_column_3"]}">${subject}</td>
1654
- <td style="text-align:${id["headline_align_column_4"]}">
1671
+ font-size:${id.header_font_size}px;">
1672
+ <td style="text-align:${id.headline_align_column_1}">${count}</td>
1673
+ <td title="${org_from}" style="text-align:${id.headline_align_column_2}">${from}</td>
1674
+ <td title="${org_subject}" style="text-align:${id.headline_align_column_3}">${subject}</td>
1675
+ <td style="text-align:${id.headline_align_column_4}">
1655
1676
  ${this.formatDate(new Date(mail.date).getTime(), "TT.MM.JJ - SS:mm")}</td>
1656
- <td title="${org_content}" style="text-align:${id["headline_align_column_5"]}">${content}</td>
1657
- <td style="text-align:${id["headline_align_column_6"]}">${seqno}</td>
1658
- <td style="text-align:${id["headline_align_column_7"]}">${attrs.flags}</td>
1659
- <td style="text-align:${id["headline_align_column_8"]}">${attrs.uid}</td>
1660
- <td style="text-align:${id["headline_align_column_9"]}">
1677
+ <td title="${org_content}" style="text-align:${id.headline_align_column_5}">${content}</td>
1678
+ <td style="text-align:${id.headline_align_column_6}">${seqno}</td>
1679
+ <td style="text-align:${id.headline_align_column_7}">${attrs.flags}</td>
1680
+ <td style="text-align:${id.headline_align_column_8}">${attrs.uid}</td>
1681
+ <td style="text-align:${id.headline_align_column_9}">
1661
1682
  <select onchange="setState('${this.namespace}.${clientID}.remote.vis_command', this.value)">
1662
1683
  ${action}</select></td>
1663
- <td style="text-align:${id["headline_align_column_10"]}">
1684
+ <td style="text-align:${id.headline_align_column_10}">
1664
1685
  <select onchange="setState('${this.namespace}.${clientID}.remote.vis_command', this.value)">
1665
1686
  ${flags}</select></td>
1666
1687
  </tr>`;
@@ -1687,7 +1708,7 @@ class Imap extends utils.Adapter {
1687
1708
  justify-content: center
1688
1709
  }`;
1689
1710
  let min = "";
1690
- if (id["jarvis"]) {
1711
+ if (id.jarvis) {
1691
1712
  div = "<div>";
1692
1713
  div_css = "";
1693
1714
  min = "min-width:100%;";
@@ -1704,28 +1725,28 @@ class Imap extends utils.Adapter {
1704
1725
  margin: 0;
1705
1726
  }
1706
1727
  body {
1707
- background-color: ${id["body_background"]}; margin: 0 auto;
1728
+ background-color: ${id.body_background}; margin: 0 auto;
1708
1729
  }
1709
1730
  p {
1710
- padding-top: 10px; padding-bottom: 10px; text-align: ${id["p_tag_text_align"]}
1731
+ padding-top: 10px; padding-bottom: 10px; text-align: ${id.p_tag_text_align}
1711
1732
  }
1712
1733
  td {
1713
- padding:${id["td_tag_cell"]}px; border:0px solid ${id["td_tag_border_color"]};
1714
- border-right:${id["td_tag_border_right"]}px solid ${id["td_tag_border_color"]};
1715
- border-bottom:${id["td_tag_border_bottom"]}px solid ${id["td_tag_border_color"]};
1734
+ padding:${id.td_tag_cell}px; border:0px solid ${id.td_tag_border_color};
1735
+ border-right:${id.td_tag_border_right}px solid ${id.td_tag_border_color};
1736
+ border-bottom:${id.td_tag_border_bottom}px solid ${id.td_tag_border_color};
1716
1737
  }
1717
1738
  table {
1718
- width: ${id["table_tag_width"]};
1719
- margin: ${id["table_tag_text_align"]};
1720
- border:1px solid ${id["table_tag_border_color"]};
1721
- border-spacing: ${id["table_tag_cell"]}px;
1739
+ width: ${id.table_tag_width};
1740
+ margin: ${id.table_tag_text_align};
1741
+ border:1px solid ${id.table_tag_border_color};
1742
+ border-spacing: ${id.table_tag_cell}px;
1722
1743
  border-collapse: collapse;
1723
1744
  }
1724
1745
  td:nth-child(1) {
1725
- width: ${id["td_tag_2_colums"]}
1746
+ width: ${id.td_tag_2_colums}
1726
1747
  }
1727
1748
  td:nth-child(2) {
1728
- width:${id["td_tag_2_colums"]}
1749
+ width:${id.td_tag_2_colums}
1729
1750
  }
1730
1751
  ${div_css}
1731
1752
  thread {
@@ -1746,60 +1767,60 @@ class Imap extends utils.Adapter {
1746
1767
  </head>
1747
1768
  <body>
1748
1769
  ${div}
1749
- <table style="${min} width:${id["header_width"]};
1750
- border:${id["header_border"]}px; border-color:${id["header_tag_border_color"]};
1751
- color:${id["header_text_color"]}; font-size:${id["header_font_size"]}px;
1752
- font-family:${id["header_font"]};
1753
- background-image: linear-gradient(42deg,${id["header_linear_color_2"]},
1754
- ${id["header_linear_color_1"]});">
1770
+ <table style="${min} width:${id.header_width};
1771
+ border:${id.header_border}px; border-color:${id.header_tag_border_color};
1772
+ color:${id.header_text_color}; font-size:${id.header_font_size}px;
1773
+ font-family:${id.header_font};
1774
+ background-image: linear-gradient(42deg,${id.header_linear_color_2},
1775
+ ${id.header_linear_color_1});">
1755
1776
  <thead>
1756
1777
  <tr>
1757
1778
  <th colspan="10" scope="colgroup">
1758
- <p style="color:${id["top_text_color"]}; font-family:${id["top_font"]};
1759
- font-size:${id["top_font_size"]}px; font-weight:${id["top_font_weight"]}">
1760
- ${id["top_text"]}&ensp;&ensp;${this.helper_translator("top_last_update")}
1779
+ <p style="color:${id.top_text_color}; font-family:${id.top_font};
1780
+ font-size:${id.top_font_size}px; font-weight:${id.top_font_weight}">
1781
+ ${id.top_text}&ensp;&ensp;${this.helper_translator("top_last_update")}
1761
1782
  ${this.formatDate(new Date(), "TT.MM.JJJJ hh:mm:ss")}</p></th>
1762
1783
  </tr>
1763
- <tr style="color:${id["headline_color"]}; height:${id["headline_height"]}px;
1764
- font-size: ${id["headline_font_size"]}px; font-weight: ${id["headline_style"]};
1765
- border-bottom: ${id["headline_underlined"]}px solid ${id["headline_underlined_color"]}">
1766
- <th style="text-align:${id["headline_align_column_1"]}; width:${id["headline_column_width_1"]}">
1767
- ${id["text_id"]}
1784
+ <tr style="color:${id.headline_color}; height:${id.headline_height}px;
1785
+ font-size: ${id.headline_font_size}px; font-weight: ${id.headline_style};
1786
+ border-bottom: ${id.headline_underlined}px solid ${id.headline_underlined_color}">
1787
+ <th style="text-align:${id.headline_align_column_1}; width:${id.headline_column_width_1}">
1788
+ ${id.text_id}
1768
1789
  </th>
1769
- <th style="text-align:${id["headline_align_column_2"]}; width:${id["headline_column_width_2"]}">
1770
- ${id["text_from"]}
1790
+ <th style="text-align:${id.headline_align_column_2}; width:${id.headline_column_width_2}">
1791
+ ${id.text_from}
1771
1792
  </th>
1772
- <th style="text-align:${id["headline_align_column_3"]}; width:${id["headline_column_width_3"]}">
1773
- ${id["text_subject"]}
1793
+ <th style="text-align:${id.headline_align_column_3}; width:${id.headline_column_width_3}">
1794
+ ${id.text_subject}
1774
1795
  </th>
1775
- <th style="text-align:${id["headline_align_column_4"]}; width:${id["headline_column_width_4"]}">
1776
- ${id["text_date"]}
1796
+ <th style="text-align:${id.headline_align_column_4}; width:${id.headline_column_width_4}">
1797
+ ${id.text_date}
1777
1798
  </th>
1778
- <th style="text-align:${id["headline_align_column_5"]}; width:${id["headline_column_width_5"]}">
1779
- ${id["text_content"]}
1799
+ <th style="text-align:${id.headline_align_column_5}; width:${id.headline_column_width_5}">
1800
+ ${id.text_content}
1780
1801
  </th>
1781
- <th style="text-align:${id["headline_align_column_6"]}; width:${id["headline_column_width_6"]}">
1782
- ${id["text_seq"]}
1802
+ <th style="text-align:${id.headline_align_column_6}; width:${id.headline_column_width_6}">
1803
+ ${id.text_seq}
1783
1804
  </th>
1784
- <th style="text-align:${id["headline_align_column_7"]}; width:${id["headline_column_width_7"]}">
1785
- ${id["text_flag"]}
1805
+ <th style="text-align:${id.headline_align_column_7}; width:${id.headline_column_width_7}">
1806
+ ${id.text_flag}
1786
1807
  </th>
1787
- <th style="text-align:${id["headline_align_column_8"]}; width:${id["headline_column_width_8"]}">
1788
- ${id["text_uid"]}
1808
+ <th style="text-align:${id.headline_align_column_8}; width:${id.headline_column_width_8}">
1809
+ ${id.text_uid}
1789
1810
  </th>
1790
- <th style="text-align:${id["headline_align_column_9"]}; width:${id["headline_column_width_9"]}">
1791
- ${id["text_move_or_copy"]}
1811
+ <th style="text-align:${id.headline_align_column_9}; width:${id.headline_column_width_9}">
1812
+ ${id.text_move_or_copy}
1792
1813
  </th>
1793
- <th style="text-align:${id["headline_align_column_10"]}; width:${id["headline_column_width_10"]}">
1794
- ${id["text_setflag"]}
1814
+ <th style="text-align:${id.headline_align_column_10}; width:${id.headline_column_width_10}">
1815
+ ${id.text_setflag}
1795
1816
  </th>
1796
1817
  </tr>
1797
1818
  </thead>
1798
1819
  <tfoot>
1799
1820
  <tr>
1800
1821
  <th colspan="10" scope="colgroup">
1801
- <p style="color:${id["top_text_color"]}; font-family:${id["top_font"]};
1802
- font-size:${id["top_font_size"]}px; font-weight:${id["top_font_weight"]}">
1822
+ <p style="color:${id.top_text_color}; font-family:${id.top_font};
1823
+ font-size:${id.top_font_size}px; font-weight:${id.top_font_weight}">
1803
1824
  ${this.helper_translator("footer", count, all)}</p></th>
1804
1825
  </tr>
1805
1826
  </tfoot>
@@ -1873,16 +1894,16 @@ class Imap extends utils.Adapter {
1873
1894
  new_json["flag"] = element.attrs && element.attrs.flags != null ? element.attrs.flags : "";
1874
1895
  new_array.push(new_json);
1875
1896
  }
1876
- await this.setStateAsync(`${id}.json`, {
1897
+ await this.setState(`${id}.json`, {
1877
1898
  val: JSON.stringify(new_array),
1878
1899
  ack: true,
1879
1900
  });
1880
1901
  if (!html) {
1881
- await this.setStateAsync(`json_table`, {
1902
+ await this.setState(`json_table`, {
1882
1903
  val: JSON.stringify(new_array),
1883
1904
  ack: true,
1884
1905
  });
1885
- await this.setStateAsync(`json_imap`, {
1906
+ await this.setState(`json_imap`, {
1886
1907
  val: id,
1887
1908
  ack: true,
1888
1909
  });
@@ -1929,7 +1950,7 @@ class Imap extends utils.Adapter {
1929
1950
  if (states && states.q != null && states.q != 0) {
1930
1951
  this.log_translator("debug", "Datapoint", `${dp.id} - ${JSON.stringify(states)}`);
1931
1952
  if (quality[states.q]) {
1932
- const isfind = dp_array.find((mes) => mes.message === quality[states.q]);
1953
+ const isfind = dp_array.find(mes => mes.message === quality[states.q]);
1933
1954
  if (isfind) {
1934
1955
  this.log_translator("debug", "Found", JSON.stringify(isfind));
1935
1956
  ++isfind.counter;
@@ -1950,7 +1971,7 @@ class Imap extends utils.Adapter {
1950
1971
  role = null;
1951
1972
  }
1952
1973
  if (quality[states.q] === "0x20 - substitute initial value") {
1953
- await this.setStateAsync(`${dp.id}`, {
1974
+ await this.setState(`${dp.id}`, {
1954
1975
  ack: true,
1955
1976
  ...role,
1956
1977
  });
@@ -1962,7 +1983,7 @@ class Imap extends utils.Adapter {
1962
1983
  }
1963
1984
  }
1964
1985
  }
1965
- await this.setStateAsync(`${deviceId}.quality`, {
1986
+ await this.setState(`${deviceId}.quality`, {
1966
1987
  val:
1967
1988
  Object.keys(dp_array).length > 0
1968
1989
  ? JSON.stringify(dp_array)
@@ -2067,7 +2088,7 @@ if (require.main !== module) {
2067
2088
  /**
2068
2089
  * @param {Partial<utils.AdapterOptions>} [options={}]
2069
2090
  */
2070
- module.exports = (options) => new Imap(options);
2091
+ module.exports = options => new Imap(options);
2071
2092
  } else {
2072
2093
  // otherwise start the instance directly
2073
2094
  new Imap();