copious-mail 0.0.0-stage → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +504 -0
  2. package/README.md +83 -2
  3. package/bin/index.js +345 -0
  4. package/client/copiousLogo.svg +123 -0
  5. package/client/hosted.html +5173 -0
  6. package/client/mail_styles.css +40 -0
  7. package/client/mikado.bundle.debug.js +1406 -0
  8. package/client/mikado.bundle.min.js +68 -0
  9. package/client/mikado.bundle.module.debug.js +1401 -0
  10. package/client/mikado.bundle.module.min.js +67 -0
  11. package/client/mikado.bundle.profiler.debug.js +1490 -0
  12. package/client/mikado.es5.debug.js +1995 -0
  13. package/client/mikado.es5.min.js +85 -0
  14. package/client/mikado.light.debug.js +535 -0
  15. package/client/mikado.light.min.js +29 -0
  16. package/client/mikado.light.module.debug.js +530 -0
  17. package/data/user_list.db +14 -0
  18. package/index.html +7242 -0
  19. package/index.js +5 -0
  20. package/jsconfig.json +32 -0
  21. package/lib/mail_repo_bridge_ops.js +1158 -0
  22. package/lib/utils.js +70 -0
  23. package/lib/websocket_con.js +248 -0
  24. package/mail_bridge.conf +10 -0
  25. package/package.json +41 -5
  26. package/svelte-src/App.svelte +2513 -0
  27. package/svelte-src/ContactGrid.svelte +98 -0
  28. package/svelte-src/FloatWindow.svelte +181 -0
  29. package/svelte-src/MessageDisplay.svelte +230 -0
  30. package/svelte-src/MessageEditor.svelte +664 -0
  31. package/svelte-src/MessageListEditor.svelte +133 -0
  32. package/svelte-src/Thing.svelte +190 -0
  33. package/svelte-src/ThingFull.svelte +117 -0
  34. package/svelte-src/ipfs_profile_proxy.js +923 -0
  35. package/svelte-src/main.js +10 -0
  36. package/svelte-src/search_box.js +69 -0
  37. package/svelte-src/utilities.js +180 -0
  38. package/test/c +28 -0
  39. package/test/copiousLogo.svg +123 -0
  40. package/test/index.html +4408 -0
  41. package/test/index.js +244 -0
  42. package/test/mail_styles.css +40 -0
  43. package/test/mikado.bundle.debug.js +1406 -0
  44. package/test/mikado.bundle.min.js +68 -0
  45. package/test/mikado.bundle.module.debug.js +1401 -0
  46. package/test/mikado.bundle.module.min.js +67 -0
  47. package/test/mikado.bundle.profiler.debug.js +1490 -0
  48. package/test/mikado.es5.debug.js +1995 -0
  49. package/test/mikado.es5.min.js +85 -0
  50. package/test/mikado.light.debug.js +535 -0
  51. package/test/mikado.light.min.js +29 -0
  52. package/test/mikado.light.module.debug.js +530 -0
  53. package/test/tpl/partial/attachment_edit.es5.js +1 -0
  54. package/test/tpl/partial/attachment_edit.html +5 -0
  55. package/test/tpl/partial/attachment_edit.js +1 -0
  56. package/test/tpl/partial/attachment_view.es5.js +1 -0
  57. package/test/tpl/partial/attachment_view.html +1 -0
  58. package/test/tpl/partial/attachment_view.js +1 -0
  59. package/test/tpl/partial/contact_list.es5.js +1 -0
  60. package/test/tpl/partial/contact_list.html +9 -0
  61. package/test/tpl/partial/contact_list.js +1 -0
  62. package/test/tpl/partial/draft_list.es5.js +1 -0
  63. package/test/tpl/partial/draft_list.html +8 -0
  64. package/test/tpl/partial/draft_list.js +1 -0
  65. package/test/tpl/partial/inbox_list.es5.js +1 -0
  66. package/test/tpl/partial/inbox_list.html +7 -0
  67. package/test/tpl/partial/inbox_list.js +1 -0
  68. package/test/tpl/partial/notify_list.es5.js +1 -0
  69. package/test/tpl/partial/notify_list.html +8 -0
  70. package/test/tpl/partial/notify_list.js +1 -0
  71. package/test/tpl/partial/sent_list.es5.js +1 -0
  72. package/test/tpl/partial/sent_list.html +7 -0
  73. package/test/tpl/partial/sent_list.js +1 -0
  74. package/test/tpl/partial/spam_list.es5.js +1 -0
  75. package/test/tpl/partial/spam_list.html +8 -0
  76. package/test/tpl/partial/spam_list.js +1 -0
  77. package/test/tpl/partial/trash_list.es5.js +1 -0
  78. package/test/tpl/partial/trash_list.html +7 -0
  79. package/test/tpl/partial/trash_list.js +1 -0
  80. package/test/tpl/partial/user.es5.js +1 -0
  81. package/test/tpl/partial/user.html +18 -0
  82. package/test/tpl/partial/user.js +1 -0
  83. package/tools/jsdoc.conf +47 -0
  84. package/tools/templates/docdash/publish.js +843 -0
  85. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  86. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  87. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  88. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  89. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  90. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  91. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  92. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  93. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  94. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  95. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  96. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  97. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  98. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  99. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  100. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  101. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  102. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  103. package/tools/templates/docdash/static/scripts/collapse.js +67 -0
  104. package/tools/templates/docdash/static/scripts/commonNav.js +28 -0
  105. package/tools/templates/docdash/static/scripts/linenumber.js +25 -0
  106. package/tools/templates/docdash/static/scripts/nav.js +12 -0
  107. package/tools/templates/docdash/static/scripts/polyfill.js +4 -0
  108. package/tools/templates/docdash/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  109. package/tools/templates/docdash/static/scripts/prettify/lang-css.js +2 -0
  110. package/tools/templates/docdash/static/scripts/prettify/prettify.js +28 -0
  111. package/tools/templates/docdash/static/scripts/search.js +99 -0
  112. package/tools/templates/docdash/static/styles/jsdoc.css +803 -0
  113. package/tools/templates/docdash/static/styles/prettify.css +80 -0
  114. package/tools/templates/docdash/tmpl/augments.tmpl +10 -0
  115. package/tools/templates/docdash/tmpl/container.tmpl +203 -0
  116. package/tools/templates/docdash/tmpl/details.tmpl +152 -0
  117. package/tools/templates/docdash/tmpl/example.tmpl +2 -0
  118. package/tools/templates/docdash/tmpl/examples.tmpl +13 -0
  119. package/tools/templates/docdash/tmpl/exceptions.tmpl +32 -0
  120. package/tools/templates/docdash/tmpl/layout.tmpl +102 -0
  121. package/tools/templates/docdash/tmpl/mainpage.tmpl +15 -0
  122. package/tools/templates/docdash/tmpl/members.tmpl +38 -0
  123. package/tools/templates/docdash/tmpl/method.tmpl +132 -0
  124. package/tools/templates/docdash/tmpl/modifies.tmpl +14 -0
  125. package/tools/templates/docdash/tmpl/namespace.tmpl +133 -0
  126. package/tools/templates/docdash/tmpl/params.tmpl +132 -0
  127. package/tools/templates/docdash/tmpl/properties.tmpl +107 -0
  128. package/tools/templates/docdash/tmpl/returns.tmpl +19 -0
  129. package/tools/templates/docdash/tmpl/source.tmpl +8 -0
  130. package/tools/templates/docdash/tmpl/tutorial.tmpl +19 -0
  131. package/tools/templates/docdash/tmpl/type.tmpl +26 -0
  132. package/tools/templates/templates/docdash/publish.js +843 -0
  133. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  134. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  135. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  136. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  137. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  138. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  139. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  140. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  141. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  142. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  143. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  144. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  145. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  146. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  147. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  148. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  149. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  150. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  151. package/tools/templates/templates/docdash/static/scripts/collapse.js +67 -0
  152. package/tools/templates/templates/docdash/static/scripts/commonNav.js +28 -0
  153. package/tools/templates/templates/docdash/static/scripts/linenumber.js +25 -0
  154. package/tools/templates/templates/docdash/static/scripts/nav.js +12 -0
  155. package/tools/templates/templates/docdash/static/scripts/polyfill.js +4 -0
  156. package/tools/templates/templates/docdash/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  157. package/tools/templates/templates/docdash/static/scripts/prettify/lang-css.js +2 -0
  158. package/tools/templates/templates/docdash/static/scripts/prettify/prettify.js +28 -0
  159. package/tools/templates/templates/docdash/static/scripts/search.js +99 -0
  160. package/tools/templates/templates/docdash/static/styles/jsdoc.css +803 -0
  161. package/tools/templates/templates/docdash/static/styles/prettify.css +80 -0
  162. package/tools/templates/templates/docdash/tmpl/augments.tmpl +10 -0
  163. package/tools/templates/templates/docdash/tmpl/container.tmpl +203 -0
  164. package/tools/templates/templates/docdash/tmpl/details.tmpl +152 -0
  165. package/tools/templates/templates/docdash/tmpl/example.tmpl +2 -0
  166. package/tools/templates/templates/docdash/tmpl/examples.tmpl +13 -0
  167. package/tools/templates/templates/docdash/tmpl/exceptions.tmpl +32 -0
  168. package/tools/templates/templates/docdash/tmpl/layout.tmpl +102 -0
  169. package/tools/templates/templates/docdash/tmpl/mainpage.tmpl +15 -0
  170. package/tools/templates/templates/docdash/tmpl/members.tmpl +38 -0
  171. package/tools/templates/templates/docdash/tmpl/method.tmpl +132 -0
  172. package/tools/templates/templates/docdash/tmpl/modifies.tmpl +14 -0
  173. package/tools/templates/templates/docdash/tmpl/namespace.tmpl +133 -0
  174. package/tools/templates/templates/docdash/tmpl/params.tmpl +132 -0
  175. package/tools/templates/templates/docdash/tmpl/properties.tmpl +107 -0
  176. package/tools/templates/templates/docdash/tmpl/returns.tmpl +19 -0
  177. package/tools/templates/templates/docdash/tmpl/source.tmpl +8 -0
  178. package/tools/templates/templates/docdash/tmpl/tutorial.tmpl +19 -0
  179. package/tools/templates/templates/docdash/tmpl/type.tmpl +26 -0
  180. package/tpl/partial/user.es5.js +1 -0
  181. package/tpl/partial/user.html +10 -0
  182. package/tpl/partial/user.js +1 -0
@@ -0,0 +1,1158 @@
1
+
2
+ /*
3
+
4
+ −32000 to −32099 Server error Reserved for implementation-defined server errors
5
+ {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null}
6
+ {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": 2},
7
+ {"jsonrpc": "2.0", "error": {"code": -32602, "message": "Invalid params", "data": "Missing required parameter: subtrahend"}, "id": 2}
8
+ {"jsonrpc": "2.0", "error": {"code": -32603, "message": "Internal error"}, "id": 4}
9
+ {"jsonrpc": "2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}
10
+
11
+ // Maybe schemas ... https://json-rpc.dev/docs
12
+
13
+ https://github.com/modelcontextprotocol/modelcontextprotocol/tree/main/schema/2026-07-28
14
+ https://modelcontextprotocol.io/docs/2026-07-28/getting-started/intro
15
+
16
+ */
17
+
18
+ // // The names of rooms which are automatically created by the system
19
+ // #define BASEROOM "Lobby"
20
+ // #define MAILROOM "Mail"
21
+ // #define SENTITEMS "Sent Items" // also for users
22
+ // #define AIDEROOM "Aide"
23
+ // #define USERCONFIGROOM "My Citadel Config"
24
+ // #define USERCALENDARROOM "Calendar"
25
+ // #define USERTASKSROOM "Tasks"
26
+ // #define USERCONTACTSROOM "Contacts"
27
+ // #define USERNOTESROOM "Notes"
28
+ // #define USERDRAFTROOM "Drafts"
29
+ // #define USERTRASHROOM "Trash"
30
+ // #define PAGELOGROOM "Sent/Received Pages"
31
+ // #define SYSCONFIGROOM "Local System Configuration"
32
+ // #define SMTP_SPOOLOUT_ROOM "__CitadelSMTPspoolout__"
33
+ // #define ADDRESS_BOOK_ROOM "Global Address Book"
34
+
35
+
36
+ // Handle some of the macro named rooms
37
+ // void convert_room_name_macros(char *towhere, size_t maxlen) {
38
+ // if (!strcasecmp(towhere, "_BASEROOM_")) {
39
+ // safestrncpy(towhere, config_get_str("c_baseroom"), maxlen);
40
+ // }
41
+ // else if (!strcasecmp(towhere, "_MAIL_")) {
42
+ // safestrncpy(towhere, MAILROOM, maxlen);
43
+ // }
44
+ // else if (!strcasecmp(towhere, "_TRASH_")) {
45
+ // safestrncpy(towhere, USERTRASHROOM, maxlen);
46
+ // }
47
+
48
+ // else if (!strcasecmp(towhere, "_DRAFTS_")) {
49
+ // safestrncpy(towhere, USERDRAFTROOM, maxlen);
50
+ // }
51
+ // else if (!strcasecmp(towhere, "_BITBUCKET_")) {
52
+ // safestrncpy(towhere, config_get_str("c_twitroom"), maxlen);
53
+ // }
54
+ // else if (!strcasecmp(towhere, "_CALENDAR_")) {
55
+ // safestrncpy(towhere, USERCALENDARROOM, maxlen);
56
+ // }
57
+ // else if (!strcasecmp(towhere, "_TASKS_")) {
58
+ // safestrncpy(towhere, USERTASKSROOM, maxlen);
59
+ // }
60
+ // else if (!strcasecmp(towhere, "_CONTACTS_")) {
61
+ // safestrncpy(towhere, USERCONTACTSROOM, maxlen);
62
+ // }
63
+ // else if (!strcasecmp(towhere, "_NOTES_")) {
64
+ // safestrncpy(towhere, USERNOTESROOM, maxlen);
65
+ // }
66
+ // }
67
+
68
+
69
+ /**
70
+ *
71
+ */
72
+ class Attachment {
73
+ constructor(id,title,data) {
74
+ this.id = id
75
+ this.title = title
76
+ this.data = data
77
+ }
78
+ }
79
+
80
+
81
+ /*
82
+ "get-mail"
83
+ "store-mail"
84
+ "remove-mail"
85
+ "send-mail"
86
+ "store-draft"
87
+ "get-contacts"
88
+ "store-contact"
89
+ "remove-contact"
90
+ */
91
+
92
+ /**
93
+ *
94
+ *
95
+ */
96
+ class LocalCacheStorage {
97
+
98
+ constructor(prev_cache) {
99
+ this.cit_interface = false
100
+ this.all_storage_classes = {
101
+ 'inbox' : {},
102
+ 'sent' : {},
103
+ 'drafts' : {},
104
+ 'spam' : {},
105
+ 'notify' : {},
106
+ 'trash' : {},
107
+ 'blog' : {},
108
+ 'source' : {},
109
+ 'contacts' : {}
110
+ }
111
+ this.current_paging = {
112
+ 'inbox' : {},
113
+ 'sent' : {},
114
+ 'drafts' : {},
115
+ 'spam' : {},
116
+ 'notify' : {},
117
+ 'trash' : {},
118
+ 'blog' : {},
119
+ 'source' : {},
120
+ 'contacts' : {}
121
+ }
122
+
123
+ this.cit_version = {
124
+ 'inbox' : "_MAIL_", // should consider that all mail may contain spam and notification (as a mail type)
125
+ 'sent' : "Sent Items",
126
+ 'drafts' : "_DRAFTS_",
127
+ 'spam' : "_MAIL_", // has to change -- this is a mail classification...
128
+ 'notify' : "_MAIL_", // has to change
129
+ 'trash' : "_TRASH_",
130
+ 'blog' : "_BLOG_",
131
+ 'source' : "_SOURCE_",
132
+ 'contacts' : "_CONTACTS_" // citadel likes to make a contact be an email...
133
+ }
134
+
135
+ this.draft_recipients = {}
136
+ //
137
+ if ( prev_cache ) {
138
+ for ( let a_class in this.all_storage_classes ) {
139
+ if ( prev_cache[a_class] ) {
140
+ this.all_storage_classes[a_class] = prev_cache[a_class]
141
+ }
142
+ }
143
+ this.draft_recipients = prev_cache.draft_recipients // an object mapping draft id's to recipients
144
+ }
145
+ }
146
+
147
+
148
+ cit_version(mtype) {
149
+ return this.cit_version[mtype]
150
+ }
151
+
152
+
153
+ set_citadel_interface(node_cit) {
154
+ this.cit_interface = node_cit
155
+ }
156
+
157
+
158
+ /**
159
+ *
160
+ * @param {array} mail_list
161
+ */
162
+ store_mails(mtype,mail_list) {
163
+ let mail_set = this.all_storage_classes[mtype]
164
+ if ( mail_set ) {
165
+ for ( let m of mail_list ) {
166
+ mail_set[m.id] = structuredClone(m)
167
+ }
168
+ }
169
+ }
170
+
171
+
172
+ /**
173
+ *
174
+ * @param {object} contact_object
175
+ */
176
+ remove_mails(mtype,mail_id_list) {
177
+ let mail_set = this.all_storage_classes[mtype]
178
+ if ( mail_set ) {
179
+ for ( let id of mail_id_list ) {
180
+ delete mail_set[id]
181
+ }
182
+ }
183
+ }
184
+
185
+
186
+ /**
187
+ *
188
+ * @param {string} mtype
189
+ * @param {string} dst_type
190
+ * @param {Array} mail_id_list
191
+ */
192
+ move_mails(mtype,dst_type,mail_id_list) {
193
+ let mail_object_list = this.get_id_emails(mtype,mail_id_list)
194
+ this.remove_mails(mtype,mail_id_list)
195
+ this.store_mails(dst_type,mail_object_list)
196
+ }
197
+
198
+
199
+ /**
200
+ *
201
+ * @param {string} mtype
202
+ * @returns {Array}
203
+ */
204
+ get_emails(mtype) {
205
+ let mail_set = this.all_storage_classes[mtype]
206
+ if ( mail_set ) {
207
+ return Object.values(mail_set)
208
+ }
209
+
210
+ console.log(mtype)
211
+ return []
212
+ }
213
+
214
+
215
+ /**
216
+ *
217
+ * @param {string} mtype
218
+ * @returns {Array}
219
+ */
220
+ get_emails_ids(mtype) {
221
+ let mail_set = this.all_storage_classes[mtype]
222
+ return Object.keys(mail_set)
223
+ }
224
+
225
+
226
+ /**
227
+ *
228
+ * @param {string} mtype
229
+ * @returns
230
+ */
231
+ get_id_emails(mtype,mail_id_list) {
232
+ let mail_set = this.all_storage_classes[mtype]
233
+ let mail_list = []
234
+ for ( let mid of mail_id_list ) {
235
+ if ( mail_set[mid] ) {
236
+ mail_list.push(mail_set[mid])
237
+ }
238
+ }
239
+ return mail_list
240
+ }
241
+
242
+
243
+
244
+ /**
245
+ *
246
+ * @param {object} contact_list
247
+ */
248
+ async store_contacts(contact_list) {
249
+ let contact_set = this.all_storage_classes['contacts']
250
+ if ( contact_set ) {
251
+ for ( let c of contact_list ) {
252
+ contact_set[c.id] = structuredClone(c)
253
+ if ( this.cit_interface ) {
254
+ await this.cit_interface.add_contact(contact_set[c.id]) // EXAMPLE
255
+ }
256
+ }
257
+ }
258
+ }
259
+
260
+
261
+ /**
262
+ *
263
+ * @param {object} contact_object
264
+ */
265
+ remove_contact(contact_object) {
266
+ let contact_set = this.all_storage_classes['contacts']
267
+ let id = contact_object.id
268
+ if ( contact_set[id] ) {
269
+ delete contact_set[id]
270
+ }
271
+ }
272
+
273
+
274
+ /**
275
+ *
276
+ * @returns {Array}
277
+ */
278
+ get_contacts() {
279
+ if ( this.cit_interface ) {
280
+ this.cit_synch_load('contacts')
281
+ }
282
+ let contact_set = this.all_storage_classes['contacts']
283
+ return Object.values(contact_set)
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @returns {Array}
289
+ */
290
+ get_contacts_ids() {
291
+ if ( this.cit_interface ) {
292
+ this.cit_synch_load('contacts')
293
+ }
294
+ let contact_set = this.all_storage_classes['contacts']
295
+ return Object.keys(contact_set)
296
+ }
297
+
298
+ // --- cit synching
299
+
300
+ // alway moved from drafts to sent...
301
+ /**
302
+ * Theoretically, all the emails going through send have recipients.
303
+ * Most likely, the objects in the list have been taken out of 'Drafts'.
304
+ *
305
+ * @param {Array} mail_obj_list
306
+ */
307
+ async send_mails(mail_obj_list) {
308
+ let promises = []
309
+ for ( let mobj of mail_obj_list ) {
310
+ promises.push(this.cit_interface.post_message(mobj))
311
+ }
312
+ await Promise.allSettled(promises)
313
+ }
314
+
315
+ /**
316
+ *
317
+ * Store to drafts, but keep the following fields in cache...
318
+ *
319
+ * "recipient" : "",
320
+ * "cc" : "",
321
+ * "bcc" : "",
322
+ *
323
+ * The recipients are stored for drafts and deleted from the message itself.
324
+ * That is because, an citadel.org mail server stored messages in rooms (local DB) only if the recipients are not listed.
325
+ * Later, the recipients must be reattached to the message object for use by the client.
326
+ *
327
+ * @param {object} mail_obj
328
+ */
329
+ async store_draft(mail_obj) {
330
+ //
331
+ if ( !(this.draft_recipients[mail_obj.id]) ) {
332
+ this.draft_recipients[mail_obj.id] = {}
333
+ }
334
+ let recips = this.draft_recipients[mail_obj.id]
335
+ if ( mail_obj.recipient ) {
336
+ recips.recipient = mail_obj.recipient
337
+ delete mail_obj.recipient
338
+ }
339
+ if ( mail_obj.cc ) {
340
+ recips.cc = mail_obj.cc
341
+ delete mail_obj.cc
342
+ }
343
+ if ( mail_obj.bcc ) {
344
+ recips.bcc = mail_obj.bcc
345
+ delete mail_obj.bcc
346
+ }
347
+ //
348
+ await this.cit_interface.goto_room('drafts')
349
+ await this.cit_interface.post_message(mail_obj)
350
+ }
351
+
352
+ /**
353
+ * The recipients of a draft have been stored.
354
+ *
355
+ * @param {object} mail_obj
356
+ */
357
+ recall_draft_recipients(mail_obj) {
358
+ let recips = this.draft_recipients[mail_obj.id]
359
+ if ( recips ) {
360
+ mail_obj.recipient = recips.recipient ? recips.recipient : ""
361
+ mail_obj.cc = recips.cc ? recips.cc : ""
362
+ mail_obj.bcc = recips.bcc ? recips.bcc : ""
363
+ }
364
+ }
365
+
366
+ /**
367
+ * The best use case for this is that a draft message is being put into trash (not delivered).
368
+ * In that case, the recipients can be deleted from memory. The user will not be able to reconstruct
369
+ * the previously written list of recipients in this case.
370
+ *
371
+ * However, if the calling methods store the object at draft_recipients[mid] in a field named differently than the
372
+ * three fields know to the citadel.org mail server, then then the user interface can provide code to restore
373
+ * recipients from that field (in case it is moved from trash).
374
+ *
375
+ * @param {Array} mail_id_list
376
+ */
377
+ drop_recipients_of_msgs(mail_id_list) {
378
+ for ( let mid of mail_id_list ) {
379
+ if ( this.draft_recipients[mid] ) {
380
+ delete this.draft_recipients[mid]
381
+ }
382
+ }
383
+ }
384
+
385
+ /**
386
+ *
387
+ * @param {string} mtype - where the message currently resides
388
+ * @param {string} salvage_field - the name of a field that the client program can pull recipients from (just in case)
389
+ * @param {Array} mail_id_list - list of mail ids
390
+ */
391
+ salvage_recipients_of_msgs(mtype,salvage_field,mail_id_list) {
392
+ for ( let mid of mail_id_list ) {
393
+ if ( this.draft_recipients[mid] ) {
394
+ let draft_recipients = this.draft_recipients[mid]
395
+ let mobj_map = this.all_storage_classes[mtype]
396
+ if ( mobj_map ) {
397
+ let mobj = mobj_map[mid]
398
+ if ( mobj ) {
399
+ mobj[salvage_field] = draft_recipients
400
+ }
401
+ }
402
+ }
403
+ }
404
+ }
405
+
406
+ async cit_synch_load(mtype) {
407
+ await this.cit_interface.goto_room(this.cit_version(mtype))
408
+ let mail_list = await this.cit_interface.get_messages("ALL")
409
+ this.store_mails(mtype,mail_list)
410
+ }
411
+
412
+
413
+
414
+ async del_from_storage(mtype,id) {
415
+ await this.user_data[user]?.cit_interface?.goto_room(this.cit_version(mtype))
416
+ await this.user_data[user]?.cit_interface?.delete_message(id)
417
+ }
418
+
419
+ async add_to_storage(mtype,mail_obj,dogo = false) {
420
+ if ( dogo ) {
421
+ await this.cit_interface.goto_room(this.cit_version(mtype))
422
+ }
423
+ await this.cit_interface.post_message(mail_obj)
424
+ }
425
+
426
+ async add_list_to_storage(mtype,mail_list) {
427
+ await this.cit_interface.goto_room(this.cit_version(mtype))
428
+ for ( let mobj of mail_list ) {
429
+ await this.add_to_storage(mtype,mobj)
430
+ }
431
+ }
432
+ }
433
+
434
+
435
+ /**
436
+ *
437
+ */
438
+ class MailRepoBridgeOps {
439
+
440
+ constructor(conf,user_db,node_cit) {
441
+ //
442
+ this.node_cit = node_cit
443
+ //
444
+ this.sim_date = new Date()
445
+ //
446
+ this.largest_id = 100
447
+ this.user_data = structuredClone(user_db)
448
+
449
+ this.initialize_user_caches(node_cit)
450
+ //
451
+ this.messages_sent = true
452
+
453
+ let cat_list = this.mail_classes()
454
+ for ( let user in user_db ) {
455
+ for ( let cat of cat_list ) {
456
+ if ( cat === "contacts" ) {
457
+ this.add_simulation_test_contacts(user,cat)
458
+ continue
459
+ }
460
+ this.add_simulation_test_data(user,cat)
461
+ }
462
+ this.add_websocket_sim_data(user)
463
+ }
464
+
465
+ let cr = conf.contact_rooms
466
+ if ( typeof cr === "string" ) {
467
+ cr = [cr]
468
+ }
469
+ if ( !(Array.isArray(cr)) ) {
470
+ cr = false
471
+ }
472
+
473
+ if ( Array.isArray(cr) && !(cr.includes("copious")) ) {
474
+ cr.unshift("copious")
475
+ }
476
+
477
+ this.contact_rooms = cr ? ["copious"] : cr
478
+ }
479
+
480
+
481
+ /**
482
+ *
483
+ * @returns {array} -- A list of mail classes assumed prior to any user specification.
484
+ */
485
+ mail_classes() {
486
+ return ['inbox', 'sent', 'drafts', 'spam', 'notify', 'trash', 'blog', 'source', 'contacts']
487
+ }
488
+
489
+ /**
490
+ *
491
+ * @param {object} node_cit -- node-citadel class instance
492
+ */
493
+ initialize_user_caches(node_cit) {
494
+ if ( typeof this.user_data === "object" ) {
495
+ for ( let user in this.user_data ) {
496
+ let prev_messages = user.mail_cache
497
+ let user_cache = new LocalCacheStorage(prev_messages)
498
+ this.user_data[user].cache = user_cache
499
+ user_cache.set_citadel_interface(node_cit)
500
+ }
501
+ }
502
+ }
503
+
504
+ //
505
+ // "error": {
506
+ // "code": -32601,
507
+ // "message": "Method not found"
508
+ // },
509
+
510
+
511
+
512
+ get_next_id() {
513
+ this.largest_id++
514
+ return this.largest_id
515
+ }
516
+
517
+ /**
518
+ *
519
+ * @param {*} user
520
+ * @param {*} mtype
521
+ */
522
+ add_simulation_test_data(user,mtype) {
523
+ //
524
+ let bunch_of_mails = [
525
+ { "id" : 1, "sender" : "mail@a.com", "subject" : "this is 1 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
526
+ "category" : "inbox",
527
+ "recipient" : "richard@myhost.local",
528
+ "cc" : "",
529
+ "attachments" : [],
530
+ "text" : "got 1 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
531
+ { "id" : 1, "sender" : "mail@s.com", "subject" : "this is 2 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
532
+ "category" : "inbox",
533
+ "recipient" : "richard@myhost.local",
534
+ "cc" : "",
535
+ "attachments" : [],
536
+ "text" : "got 2 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
537
+ { "id" : 1, "sender" : "mail@d.com", "subject" : "this is 3 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
538
+ "category" : "inbox",
539
+ "recipient" : "richard@myhost.local",
540
+ "cc" : "",
541
+ "attachments" : [],
542
+ "text" : "got 3 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
543
+ { "id" : 1, "sender" : "mail@f.com", "subject" : "this is 4 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
544
+ "category" : "inbox",
545
+ "recipient" : "richard@myhost.local",
546
+ "cc" : "",
547
+ "attachments" : [],
548
+ "text" : "got 4 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
549
+ { "id" : 1, "sender" : "mail@g.com", "subject" : "this is 5 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
550
+ "category" : "inbox",
551
+ "recipient" : "richard@myhost.local",
552
+ "cc" : "",
553
+ "attachments" : [],
554
+ "text" : "got 5 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
555
+ ]
556
+
557
+ let new_mail_bunch = bunch_of_mails
558
+
559
+ for ( let m of new_mail_bunch ) {
560
+ m.id = this.get_next_id()
561
+ //
562
+ let d = new Date()
563
+ m.date = d.toLocaleString()
564
+ m.timestamp = d.getTime()
565
+ m.category = mtype
566
+ if ( mtype === 'blog' ) {
567
+ m.created_when = d.toLocaleString()
568
+ m.updated_when = d.toLocaleString()
569
+ m. description = "this is a test"
570
+ m.score = 1.0,
571
+ m.keys = "sensless,common,often"
572
+ }
573
+ }
574
+ if ( (mtype === "drafts") || (mtype === "sent") ) {
575
+ for ( let m of new_mail_bunch ) {
576
+ let recip = m.recipient
577
+ m.recipient = m.sender
578
+ m.sender = recip
579
+ }
580
+ }
581
+
582
+ let j = 0
583
+ for ( let m of new_mail_bunch ) {
584
+ let a1 = new Attachment(this.get_next_id(),`at-test ${j++}`,"This is a test of the attachments")
585
+ m.attachments.push(a1)
586
+ let a2 = new Attachment(this.get_next_id(),`at-test ${j++}`,"This is a test of more attachments")
587
+ m.attachments.push(a2)
588
+ }
589
+
590
+ this.user_data[user].cache.store_mails(mtype,new_mail_bunch)
591
+ }
592
+
593
+
594
+
595
+ async add_simulation_test_contacts(user,cat) {
596
+ let bunch_of_contacts = [
597
+ { "id" : 1, "email" : "mail@a.com", "name" : "this is 1 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
598
+ "text" : "got 1 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
599
+ { "id" : 1, "email" : "mail@s.com", "name" : "this is 2 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
600
+ "text" : "got 2 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
601
+ { "id" : 1, "email" : "mail@d.com", "name" : "this is 3 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
602
+ "text" : "got 3 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
603
+ { "id" : 1, "email" : "mail@f.com", "name" : "this is 4 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
604
+ "text" : "got 4 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
605
+ { "id" : 1, "email" : "mail@g.com", "name" : "this is 5 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
606
+ "text" : "got 5 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
607
+ ]
608
+ //
609
+ let new_contact_bunch = structuredClone(bunch_of_contacts)
610
+ for ( let c of new_contact_bunch ) {
611
+ c.id = this.get_next_id()
612
+ //
613
+ let d = new Date()
614
+ c.date = d.toLocaleString()
615
+ c.timestamp = d.getTime()
616
+ c._count_edits = 1
617
+ }
618
+
619
+ await this.user_data[user].cache.store_contacts(new_contact_bunch)
620
+ }
621
+
622
+
623
+ add_websocket_sim_data(user) {
624
+ // TESTING
625
+ let date = new Date()
626
+ let start_id_for_testing = 1;
627
+ let one_mail = { "id" : start_id_for_testing++, "sender" : "mail@b.com",
628
+ "subject" : "this is a test",
629
+ "recipient" : "richard@myhost.local",
630
+ "cc" : "",
631
+ "date" : date.toLocaleString(),
632
+ "timestamp" : date.getTime(),
633
+ "category" : "inbox",
634
+ "text" : "every message might have some text",
635
+ "attachments" : [],
636
+ "_count_edits" : 1, "_saved_updates" : []
637
+ }
638
+
639
+ let one_sent = { "id" : start_id_for_testing++,
640
+ "recipient" : "mail@b.com", "subject" : "this is a test",
641
+ "cc" : "",
642
+ "sender" : "richard@myhost.local",
643
+ "date" : date.toLocaleString(),
644
+ "category" : "sent",
645
+ "timestamp" : date.getTime(),
646
+ "text" : "sent message that might have some text",
647
+ "attachments" : [],
648
+ "_count_edits" : 1, "_saved_updates" : []
649
+ }
650
+
651
+
652
+ let one_drafts = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
653
+ "cc" : "",
654
+ "sender" : "richard@myhost.local",
655
+ "date" : date.toLocaleString(),
656
+ "timestamp" : date.getTime(),
657
+ "category" : "drafts",
658
+ "text" : "wrote message that might have some text",
659
+ "attachments" : [],
660
+ "_count_edits" : 1, "_saved_updates" : []
661
+ }
662
+
663
+
664
+ let one_contact = { "id" : start_id_for_testing++, "email" : "mail@b.com",
665
+ "name" : "Samkin Napkin",
666
+ "date" : date.toLocaleString(),
667
+ "timestamp" : date.getTime(),
668
+ "text" : "some kid in L.A.",
669
+ "_count_edits" : 1, "_saved_updates" : []
670
+ }
671
+
672
+
673
+ let one_blog = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
674
+ "cc" : "",
675
+ "sender" : "richard@myhost.local",
676
+ "date" : date.toLocaleString(),
677
+ "timestamp" : date.getTime(),
678
+ "created_when" : date.toLocaleString(),
679
+ "updated_when" : date.toLocaleString(),
680
+ "description" : "this is a test",
681
+ "score" : 1.0,
682
+ "keys" : "sensless,common,often",
683
+ "category" : "blog",
684
+ "text" : "wrote message that might have some text",
685
+ "attachments" : [],
686
+ "_count_edits" : 1, "_saved_updates" : []
687
+ }
688
+
689
+ let one_source = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
690
+ "cc" : "",
691
+ "sender" : "richard@myhost.local",
692
+ "date" : date.toLocaleString(),
693
+ "timestamp" : date.getTime(),
694
+ "created_when" : date.toLocaleString(),
695
+ "updated_when" : date.toLocaleString(),
696
+ "description" : "this is a test",
697
+ "score" : 1.0,
698
+ "keys" : "sensless,common,often",
699
+ "category" : "source",
700
+ "text" : "wrote message that might have some text",
701
+ "attachments" : [],
702
+ "_count_edits" : 1, "_saved_updates" : []
703
+ }
704
+
705
+ this.websocket_test_data = {
706
+ "inbox" : [one_mail],
707
+ "drafts" : [one_drafts],
708
+ "sent" : [one_sent],
709
+ "contacts" : [one_contact],
710
+ "blog" : [one_blog],
711
+ "source" : [one_source]
712
+ }
713
+
714
+ }
715
+
716
+
717
+ /**
718
+ *
719
+ * @param {object} params
720
+ * @returns {Array}
721
+ */
722
+ async gather_and_output_emails(params) {
723
+ //
724
+ let mtype = params.mail_type
725
+ if ( mtype === undefined ) {
726
+ mtype = params.blg_entry_type
727
+ }
728
+ let user = params.user
729
+
730
+ if ( this.user_data[user] ) {
731
+ // await this.user_data[user].cit_synch_load(mtype)
732
+ //
733
+ if ( params.id_only ) {
734
+ return this.user_data[user]?.cache.get_emails_ids(ctype)
735
+ } else {
736
+ let emails = this.user_data[user]?.cache.get_emails(mtype)
737
+ if ( mtype === 'drafts' ) {
738
+ for ( let mail_obj of emails ) {
739
+ this.user_data[user]?.recall_draft_recipients(mail_obj)
740
+ }
741
+ }
742
+ return emails
743
+ }
744
+ }
745
+ //
746
+ }
747
+
748
+
749
+ /**
750
+ *
751
+ * @param {object} params
752
+ * @returns
753
+ */
754
+ async gather_and_output_contacts(params) {
755
+ let user = params.user
756
+ let contacts = false
757
+ if ( params.id_only ) {
758
+ contacts = this.user_data[user].cache.get_contacts_ids()
759
+ } else {
760
+ contacts = this.user_data[user].cache.get_contacts()
761
+ }
762
+ return contacts
763
+ }
764
+
765
+
766
+ /**
767
+ *
768
+ * @param {string} id
769
+ * @param {string} method
770
+ * @param {any} params
771
+ * @returns {object}
772
+ */
773
+ async handle_rpc(method,params) {
774
+ //
775
+ let results = {
776
+ "error" : {"code": -32601, "message": "Method not found"}
777
+ }
778
+ //
779
+ switch (method) {
780
+ case "get-mail" : {
781
+ results = {
782
+ "result" : await this.gather_and_output_emails(params)
783
+ }
784
+ break;
785
+ }
786
+ case "store-mail" : {
787
+ let mail_list = params.params
788
+ if ( mail_list && Array.isArray(mail_list) && mail_list.length ) {
789
+ let mtype = params.mail_type
790
+ let user = params.user
791
+ this.user_data[user].cache.store_mails(mtype,mail_list)
792
+ await this.user_data[user].cache.add_list_to_storage(mtype,mail_list)
793
+ results = {
794
+ "result" : true
795
+ }
796
+ }
797
+ break;
798
+ }
799
+ case "remove-mail" : {
800
+ let mail_list = params.params
801
+ if ( mail_list && Array.isArray(mail_list) && mail_list.length ) {
802
+ let mtype = params.mail_type
803
+ let user = params.user
804
+ this.user_data[user].cache.remove_mails(mtype,mail_list)
805
+ results = {
806
+ "result" : true
807
+ }
808
+ }
809
+ break;
810
+ }
811
+ case "send-mail" : {
812
+ let mail_obj_list = params.params
813
+ if ( mail_obj_list && Array.isArray(mail_obj_list) && mail_obj_list.length ) {
814
+ let mtype = 'drafts'
815
+ let dst_type = 'sent'
816
+ let user = params.user
817
+ let mail_id_list = mail_obj_list.map(obj => { return obj.id })
818
+ await this.user_data[user].send_mails(mail_obj_list)
819
+ this.user_data[user].cache.salvage_recipients_of_msgs(mtype,salvage_field,mail_id_list)
820
+ this.user_data[user].cache.drop_recipients_of_msgs(mail_id_list)
821
+ this.user_data[user].cache.move_mails(mtype,dst_type,mail_id_list)
822
+ // not clear if this next line needs to be called...
823
+ await this.user_data[user]?.cit_interface?.move_message_list(mail_id_list,dst_type)
824
+ results = {
825
+ "result" : true
826
+ }
827
+ }
828
+ break;
829
+ }
830
+
831
+ case "move-mail" : {
832
+ let mail_id_list = params.params
833
+ if ( mail_id_list && Array.isArray(mail_id_list) && mail_id_list.length ) {
834
+ let mtype = params.mail_type
835
+ let dst_type = params.to_mail_type
836
+ let user = params.user
837
+ if ( mtype === "drafts" ) {
838
+ this.user_data[user].cache.salvage_recipients_of_msgs(mtype,salvage_field,mail_id_list)
839
+ this.user_data[user].cache.drop_recipients_of_msgs(mail_id_list)
840
+ }
841
+ this.user_data[user].cache.move_mails(mtype,dst_type,mail_id_list)
842
+ await this.user_data[user]?.cit_interface?.move_message_list(mail_id_list,dst_type)
843
+ results = {
844
+ "result" : true
845
+ }
846
+ }
847
+ break;
848
+ }
849
+
850
+ case "store-draft" : {
851
+ let mail_object = params.params
852
+ if ( mail_object ) {
853
+ let mtype = params.mail_type
854
+ let user = params.user
855
+ this.user_data[user].cache.store_mails(mtype,[mail_object])
856
+ await this.user_data[user]?.cit_interface?.store_draft(mail_object)
857
+ results = {
858
+ "result" : true
859
+ }
860
+ }
861
+ break;
862
+ }
863
+ case "get-contacts" : {
864
+ results = {
865
+ "result" : await this.gather_and_output_contacts(params)
866
+ }
867
+ break;
868
+ }
869
+ case "store-contact" : {
870
+ let contact_object = params.params
871
+ if ( contact_object ) {
872
+ // let mtype = params.mail_type
873
+ let user = params.user
874
+ await this.user_data[user].cache.store_contacts([contact_object])
875
+ results = {
876
+ "result" : true
877
+ }
878
+ }
879
+ break;
880
+ }
881
+ case "remove-contact" : {
882
+ let contact_object = params.params
883
+ if ( contact_object ) {
884
+ // let mtype = params.mail_type
885
+ let user = params.user
886
+ this.user_data[user].cache.remove_contact(contact_object)
887
+ await this.user_data[user].cache.del_from_storage('contacts',contact_object.id)
888
+ results = {
889
+ "result" : true
890
+ }
891
+ }
892
+ break;
893
+ }
894
+
895
+ }
896
+
897
+ // ---- ---- ---- ---- ---- ----
898
+ // //
899
+ // ---- ---- ---- ---- ---- ----
900
+ return results
901
+ }
902
+
903
+
904
+ /**
905
+ *
906
+ * 'static.contact_message' -- a particular type of post that goes to the contact room of a concern (from front page)
907
+ * 'static.posts' --
908
+ * 'static.contacts' -- in particular a contact made by a copious-mail interface (a human page app)
909
+ *
910
+ * @param {string} table
911
+ * @param {string} method
912
+ * @param {object} params
913
+ */
914
+ async store_item(table,method,params) {
915
+ let results = {
916
+ "error" : {"code": -32601, "message": "Method not found"}
917
+ }
918
+
919
+ if ( method && params ) {
920
+ switch (table) {
921
+ case "contact_message" : { // this is mail deliver to a room that is the designated front-page contact room
922
+ let concern = params.concern
923
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
924
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
925
+ params.user = room_addr
926
+ return await this.handle_rpc("store-mail",params)
927
+ }
928
+ break;
929
+ }
930
+ case "messages" : { // part of mu-lite
931
+ let mtype = params.mail_type
932
+ if ( ['drafts','contacts'].includes(mtype) ) {
933
+ if ( mtype === 'drafts' ) {
934
+ return await this.handle_rpc("store-draft",params)
935
+ } else if ( mtype === 'contacts' ) { // a user contact v.s. the contact room for front page contacts
936
+ return await this.handle_rpc("store-mail",params)
937
+ }
938
+
939
+ } else {
940
+ return await this.handle_rpc("store-mail",params)
941
+ }
942
+ }
943
+ }
944
+
945
+ }
946
+
947
+ return results
948
+ }
949
+
950
+
951
+
952
+ /**
953
+ *
954
+ * 'static.contact_message' -- a particular type of post that goes to the contact room of a concern (from front page)
955
+ * 'static.posts' --
956
+ * 'static.contacts' -- in particular a contact made by a copious-mail interface (a human page app)
957
+ *
958
+ * @param {string} table
959
+ * @param {string} method
960
+ * @param {object} params
961
+ */
962
+ async get_items(table,id_only,method,params) {
963
+ let results = {
964
+ "error" : {"code": -32601, "message": "Method not found"}
965
+ }
966
+
967
+ if ( method && params ) {
968
+ params.id_only = id_only
969
+ switch (table) {
970
+ case "contact_message" : { // this is mail deliver to a room that is the designated front-page contact room
971
+ let concern = params.concern
972
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
973
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
974
+ params.user = room_addr
975
+ return await this.handle_rpc("get-mail",params)
976
+ }
977
+ break;
978
+ }
979
+ case "messages" : { // part of mu-lite
980
+ let mtype = params.mail_type
981
+ if ( ['drafts','contacts'].includes(mtype) ) {
982
+ if ( mtype === 'drafts' ) {
983
+ return await this.handle_rpc("get-draft",params)
984
+ } else if ( mtype === 'contacts' ) { // a user contact v.s. the contact room for front page contacts
985
+ return await this.handle_rpc("get-contacts",params) // plural
986
+ }
987
+
988
+ } else {
989
+ return await this.handle_rpc("get-mail",params)
990
+ }
991
+ }
992
+ }
993
+
994
+ }
995
+
996
+ return results
997
+ }
998
+
999
+
1000
+ /**
1001
+ *
1002
+ * @param {*} table
1003
+ * @param {*} params
1004
+ * @returns
1005
+ */
1006
+ async remove_items(table,params) {
1007
+ //
1008
+ let results = {
1009
+ "error" : {"code": -32601, "message": "Method not found"}
1010
+ }
1011
+
1012
+ let method = "remove-contact"
1013
+ method = "remove-mail"
1014
+
1015
+
1016
+ if ( method && params ) {
1017
+ switch (table) {
1018
+ case "contact_message" : {
1019
+ let concern = params.concern
1020
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
1021
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
1022
+ params.user = room_addr
1023
+ return await this.handle_rpc("remove-contact",params)
1024
+ }
1025
+ break;
1026
+ }
1027
+ case "messages" : {
1028
+ let mtype = params.mail_type
1029
+ if ( ['contacts'].includes(mtype) ) {
1030
+ return await this.handle_rpc("remove-contact",params)
1031
+ } else {
1032
+ return await this.handle_rpc("remove-contact",params)
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ return results
1039
+ }
1040
+
1041
+ //
1042
+ /**
1043
+ *
1044
+ * @param {string} method
1045
+ * @param {any} params
1046
+ * @returns {boolean}
1047
+ */
1048
+ handle_rpc_notify(method,params) {
1049
+ return true
1050
+ }
1051
+
1052
+
1053
+ /**
1054
+ *
1055
+ * @returns {object|string}
1056
+ */
1057
+ sendable_proc_data() { // should be an update on emails, etc.
1058
+ return (new Date()).toLocaleString()
1059
+ }
1060
+
1061
+
1062
+ /**
1063
+ *
1064
+ * @returns {object|boolean}
1065
+ */
1066
+ async ws_handle_user_update_req(mail_req) {
1067
+ let sendable = this.websocket_test_data
1068
+ let op_message = {
1069
+ "op" : "all-updates",
1070
+ "data" : sendable
1071
+ }
1072
+ return op_message
1073
+ }
1074
+
1075
+ /**
1076
+ *
1077
+ * @returns {object|boolean}
1078
+ */
1079
+ async ws_data_updates() {
1080
+ //
1081
+ if ( !(this.messages_sent) ) {
1082
+ let sendable = this.websocket_test_data
1083
+ let op_message = {
1084
+ "op" : "all-updates",
1085
+ "data" : sendable
1086
+ }
1087
+ return op_message
1088
+ }
1089
+ //
1090
+ return false
1091
+ }
1092
+
1093
+ /**
1094
+ *
1095
+ * @param {boolean} sent
1096
+ */
1097
+ update_messages_sent(sent) {
1098
+ this.messages_sent = sent
1099
+ }
1100
+
1101
+
1102
+ /**
1103
+ *
1104
+ * @param {object} ext_repo_conf
1105
+ */
1106
+ file_upload_bridge(ext_repo_conf) {
1107
+ // for upload operations ... using the file uploading from the cit server
1108
+ }
1109
+
1110
+
1111
+
1112
+
1113
+ /**
1114
+ *
1115
+ * @param {object} obj
1116
+ * @returns
1117
+ */
1118
+ get_asset_file(obj) {
1119
+ let file_name = obj.file
1120
+ obj.data = "this is a test: " + file_name
1121
+ return true
1122
+ }
1123
+
1124
+ /**
1125
+ *
1126
+ * @param {object} obj
1127
+ * @
1128
+ *
1129
+ * returns
1130
+ */
1131
+ get_app_file(obj) {
1132
+ let file_name = obj.file
1133
+ obj.data = "this is a test: " + file_name
1134
+ return true
1135
+ }
1136
+
1137
+
1138
+ async add_files(data) {
1139
+ //
1140
+ }
1141
+
1142
+ async update_files(data) {
1143
+ //
1144
+ }
1145
+
1146
+ async get_active_user(id) {
1147
+
1148
+ }
1149
+
1150
+ async add_active_user(value) {
1151
+ let id = value.id
1152
+ }
1153
+
1154
+ }
1155
+
1156
+
1157
+
1158
+ module.exports = MailRepoBridgeOps