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