copious-mail 0.0.0-stage → 0.9.1

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 +143 -2
  3. package/bin/index.js +345 -0
  4. package/client/copiousLogo.svg +123 -0
  5. package/client/hosted.html +5259 -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 +1177 -0
  22. package/lib/utils.js +70 -0
  23. package/lib/websocket_con.js +249 -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,1177 @@
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.mail_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.server_token_name = {
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
+ server_token_name(mtype) {
149
+ return this.server_token_name[mtype]
150
+ }
151
+
152
+
153
+ set_mail_interface(mail_server_interface) {
154
+ this.mail_interface = mail_server_interface
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.mail_interface ) {
254
+ await this.mail_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.mail_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.mail_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.mail_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.mail_interface.goto_room('drafts')
349
+ await this.mail_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
+ /**
407
+ *
408
+ * @param {string} mtype
409
+ */
410
+ async cit_synch_load(mtype) {
411
+ await this.mail_interface.goto_room(this.server_token_name(mtype))
412
+ let mail_list = await this.mail_interface.get_messages("ALL")
413
+ this.store_mails(mtype,mail_list)
414
+ }
415
+
416
+
417
+ /**
418
+ *
419
+ * @param {string} mtype
420
+ * @param {string} id
421
+ */
422
+ async del_from_storage(mtype,id) {
423
+ await this.user_data[user]?.mail_interface?.goto_room(this.server_token_name(mtype))
424
+ await this.user_data[user]?.mail_interface?.delete_message(id)
425
+ }
426
+
427
+ /**
428
+ *
429
+ * @param {string} mtype
430
+ * @param {object} mail_obj
431
+ * @param {boolean} dogo
432
+ */
433
+ async add_to_storage(mtype,mail_obj,dogo = false) {
434
+ if ( dogo ) {
435
+ await this.mail_interface.goto_room(this.server_token_name(mtype))
436
+ }
437
+ await this.mail_interface.post_message(mail_obj)
438
+ }
439
+
440
+ /**
441
+ *
442
+ * @param {string} mtype
443
+ * @param {Array} mail_list
444
+ */
445
+ async add_list_to_storage(mtype,mail_list) {
446
+ await this.mail_interface.goto_room(this.server_token_name(mtype))
447
+ for ( let mobj of mail_list ) {
448
+ await this.add_to_storage(mtype,mobj)
449
+ }
450
+ }
451
+ }
452
+
453
+
454
+ /**
455
+ *
456
+ */
457
+ class MailRepoBridgeOps {
458
+
459
+ constructor(conf,user_db,mail_server_interface) {
460
+ //
461
+ this.node_cit = mail_server_interface
462
+ //
463
+ this.sim_date = new Date()
464
+ //
465
+ this.largest_id = 100
466
+ this.user_data = structuredClone(user_db)
467
+
468
+ this.initialize_user_caches(mail_server_interface)
469
+ //
470
+ this.messages_sent = true
471
+
472
+ let cat_list = this.mail_classes()
473
+ for ( let user in user_db ) {
474
+ for ( let cat of cat_list ) {
475
+ if ( cat === "contacts" ) {
476
+ this.add_simulation_test_contacts(user,cat)
477
+ continue
478
+ }
479
+ this.add_simulation_test_data(user,cat)
480
+ }
481
+ this.add_websocket_sim_data(user)
482
+ }
483
+
484
+ let cr = conf.contact_rooms
485
+ if ( typeof cr === "string" ) {
486
+ cr = [cr]
487
+ }
488
+ if ( !(Array.isArray(cr)) ) {
489
+ cr = false
490
+ }
491
+
492
+ if ( Array.isArray(cr) && !(cr.includes("copious")) ) {
493
+ cr.unshift("copious")
494
+ }
495
+
496
+ this.contact_rooms = cr ? ["copious"] : cr
497
+ }
498
+
499
+
500
+ /**
501
+ *
502
+ * @returns {array} -- A list of mail classes assumed prior to any user specification.
503
+ */
504
+ mail_classes() {
505
+ return ['inbox', 'sent', 'drafts', 'spam', 'notify', 'trash', 'blog', 'source', 'contacts']
506
+ }
507
+
508
+ /**
509
+ *
510
+ * @param {object} node_cit -- node-citadel class instance
511
+ */
512
+ initialize_user_caches(mail_server_interface) {
513
+ if ( typeof this.user_data === "object" ) {
514
+ for ( let user in this.user_data ) {
515
+ let prev_messages = user.mail_cache
516
+ let user_cache = new LocalCacheStorage(prev_messages)
517
+ this.user_data[user].cache = user_cache
518
+ user_cache.set_mail_interface(mail_server_interface)
519
+ }
520
+ }
521
+ }
522
+
523
+ //
524
+ // "error": {
525
+ // "code": -32601,
526
+ // "message": "Method not found"
527
+ // },
528
+
529
+
530
+
531
+ get_next_id() {
532
+ this.largest_id++
533
+ return this.largest_id
534
+ }
535
+
536
+ /**
537
+ *
538
+ * @param {*} user
539
+ * @param {*} mtype
540
+ */
541
+ add_simulation_test_data(user,mtype) {
542
+ //
543
+ let bunch_of_mails = [
544
+ { "id" : 1, "sender" : "mail@a.com", "subject" : "this is 1 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
545
+ "category" : "inbox",
546
+ "recipient" : "richard@myhost.local",
547
+ "cc" : "",
548
+ "attachments" : [],
549
+ "text" : "got 1 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
550
+ { "id" : 1, "sender" : "mail@s.com", "subject" : "this is 2 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
551
+ "category" : "inbox",
552
+ "recipient" : "richard@myhost.local",
553
+ "cc" : "",
554
+ "attachments" : [],
555
+ "text" : "got 2 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
556
+ { "id" : 1, "sender" : "mail@d.com", "subject" : "this is 3 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
557
+ "category" : "inbox",
558
+ "recipient" : "richard@myhost.local",
559
+ "cc" : "",
560
+ "attachments" : [],
561
+ "text" : "got 3 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
562
+ { "id" : 1, "sender" : "mail@f.com", "subject" : "this is 4 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
563
+ "category" : "inbox",
564
+ "recipient" : "richard@myhost.local",
565
+ "cc" : "",
566
+ "attachments" : [],
567
+ "text" : "got 4 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
568
+ { "id" : 1, "sender" : "mail@g.com", "subject" : "this is 5 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
569
+ "category" : "inbox",
570
+ "recipient" : "richard@myhost.local",
571
+ "cc" : "",
572
+ "attachments" : [],
573
+ "text" : "got 5 message that might have some text", "_count_edits" : 1, "_saved_updates" : [] },
574
+ ]
575
+
576
+ let new_mail_bunch = bunch_of_mails
577
+
578
+ for ( let m of new_mail_bunch ) {
579
+ m.id = this.get_next_id()
580
+ //
581
+ let d = new Date()
582
+ m.date = d.toLocaleString()
583
+ m.timestamp = d.getTime()
584
+ m.category = mtype
585
+ if ( mtype === 'blog' ) {
586
+ m.created_when = d.toLocaleString()
587
+ m.updated_when = d.toLocaleString()
588
+ m. description = "this is a test"
589
+ m.score = 1.0,
590
+ m.keys = "sensless,common,often"
591
+ }
592
+ }
593
+ if ( (mtype === "drafts") || (mtype === "sent") ) {
594
+ for ( let m of new_mail_bunch ) {
595
+ let recip = m.recipient
596
+ m.recipient = m.sender
597
+ m.sender = recip
598
+ }
599
+ }
600
+
601
+ let j = 0
602
+ for ( let m of new_mail_bunch ) {
603
+ let a1 = new Attachment(this.get_next_id(),`at-test ${j++}`,"This is a test of the attachments")
604
+ m.attachments.push(a1)
605
+ let a2 = new Attachment(this.get_next_id(),`at-test ${j++}`,"This is a test of more attachments")
606
+ m.attachments.push(a2)
607
+ }
608
+
609
+ this.user_data[user].cache.store_mails(mtype,new_mail_bunch)
610
+ }
611
+
612
+
613
+
614
+ async add_simulation_test_contacts(user,cat) {
615
+ let bunch_of_contacts = [
616
+ { "id" : 1, "email" : "mail@a.com", "name" : "this is 1 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
617
+ "text" : "got 1 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
618
+ { "id" : 1, "email" : "mail@s.com", "name" : "this is 2 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
619
+ "text" : "got 2 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
620
+ { "id" : 1, "email" : "mail@d.com", "name" : "this is 3 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
621
+ "text" : "got 3 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
622
+ { "id" : 1, "email" : "mail@f.com", "name" : "this is 4 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
623
+ "text" : "got 4 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
624
+ { "id" : 1, "email" : "mail@g.com", "name" : "this is 5 test", "date" : this.sim_date.toLocaleString(), "timestamp" : this.sim_date.getTime(),
625
+ "text" : "got 5 contact that might have some text", "_count_edits" : 0, "_saved_updates" : [] },
626
+ ]
627
+ //
628
+ let new_contact_bunch = structuredClone(bunch_of_contacts)
629
+ for ( let c of new_contact_bunch ) {
630
+ c.id = this.get_next_id()
631
+ //
632
+ let d = new Date()
633
+ c.date = d.toLocaleString()
634
+ c.timestamp = d.getTime()
635
+ c._count_edits = 1
636
+ }
637
+
638
+ await this.user_data[user].cache.store_contacts(new_contact_bunch)
639
+ }
640
+
641
+
642
+ add_websocket_sim_data(user) {
643
+ // TESTING
644
+ let date = new Date()
645
+ let start_id_for_testing = 1;
646
+ let one_mail = { "id" : start_id_for_testing++, "sender" : "mail@b.com",
647
+ "subject" : "this is a test",
648
+ "recipient" : "richard@myhost.local",
649
+ "cc" : "",
650
+ "date" : date.toLocaleString(),
651
+ "timestamp" : date.getTime(),
652
+ "category" : "inbox",
653
+ "text" : "every message might have some text",
654
+ "attachments" : [],
655
+ "_count_edits" : 1, "_saved_updates" : []
656
+ }
657
+
658
+ let one_sent = { "id" : start_id_for_testing++,
659
+ "recipient" : "mail@b.com", "subject" : "this is a test",
660
+ "cc" : "",
661
+ "sender" : "richard@myhost.local",
662
+ "date" : date.toLocaleString(),
663
+ "category" : "sent",
664
+ "timestamp" : date.getTime(),
665
+ "text" : "sent message that might have some text",
666
+ "attachments" : [],
667
+ "_count_edits" : 1, "_saved_updates" : []
668
+ }
669
+
670
+
671
+ let one_drafts = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
672
+ "cc" : "",
673
+ "sender" : "richard@myhost.local",
674
+ "date" : date.toLocaleString(),
675
+ "timestamp" : date.getTime(),
676
+ "category" : "drafts",
677
+ "text" : "wrote message that might have some text",
678
+ "attachments" : [],
679
+ "_count_edits" : 1, "_saved_updates" : []
680
+ }
681
+
682
+
683
+ let one_contact = { "id" : start_id_for_testing++, "email" : "mail@b.com",
684
+ "name" : "Samkin Napkin",
685
+ "date" : date.toLocaleString(),
686
+ "timestamp" : date.getTime(),
687
+ "text" : "some kid in L.A.",
688
+ "_count_edits" : 1, "_saved_updates" : []
689
+ }
690
+
691
+
692
+ let one_blog = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
693
+ "cc" : "",
694
+ "sender" : "richard@myhost.local",
695
+ "date" : date.toLocaleString(),
696
+ "timestamp" : date.getTime(),
697
+ "created_when" : date.toLocaleString(),
698
+ "updated_when" : date.toLocaleString(),
699
+ "description" : "this is a test",
700
+ "score" : 1.0,
701
+ "keys" : "sensless,common,often",
702
+ "category" : "blog",
703
+ "text" : "wrote message that might have some text",
704
+ "attachments" : [],
705
+ "_count_edits" : 1, "_saved_updates" : []
706
+ }
707
+
708
+ let one_source = { "id" : start_id_for_testing++, "recipient" : "mail@b.com", "subject" : "this is a test",
709
+ "cc" : "",
710
+ "sender" : "richard@myhost.local",
711
+ "date" : date.toLocaleString(),
712
+ "timestamp" : date.getTime(),
713
+ "created_when" : date.toLocaleString(),
714
+ "updated_when" : date.toLocaleString(),
715
+ "description" : "this is a test",
716
+ "score" : 1.0,
717
+ "keys" : "sensless,common,often",
718
+ "category" : "source",
719
+ "text" : "wrote message that might have some text",
720
+ "attachments" : [],
721
+ "_count_edits" : 1, "_saved_updates" : []
722
+ }
723
+
724
+ this.websocket_test_data = {
725
+ "inbox" : [one_mail],
726
+ "drafts" : [one_drafts],
727
+ "sent" : [one_sent],
728
+ "contacts" : [one_contact],
729
+ "blog" : [one_blog],
730
+ "source" : [one_source]
731
+ }
732
+
733
+ }
734
+
735
+
736
+ /**
737
+ *
738
+ * @param {object} params
739
+ * @returns {Array}
740
+ */
741
+ async gather_and_output_emails(params) {
742
+ //
743
+ let mtype = params.mail_type
744
+ if ( mtype === undefined ) {
745
+ mtype = params.blg_entry_type
746
+ }
747
+ let user = params.user
748
+
749
+ if ( this.user_data[user] ) {
750
+ // await this.user_data[user].cit_synch_load(mtype)
751
+ //
752
+ if ( params.id_only ) {
753
+ return this.user_data[user]?.cache.get_emails_ids(ctype)
754
+ } else {
755
+ let emails = this.user_data[user]?.cache.get_emails(mtype)
756
+ if ( mtype === 'drafts' ) {
757
+ for ( let mail_obj of emails ) {
758
+ this.user_data[user]?.recall_draft_recipients(mail_obj)
759
+ }
760
+ }
761
+ return emails
762
+ }
763
+ }
764
+ //
765
+ }
766
+
767
+
768
+ /**
769
+ *
770
+ * @param {object} params
771
+ * @returns
772
+ */
773
+ async gather_and_output_contacts(params) {
774
+ let user = params.user
775
+ let contacts = false
776
+ if ( params.id_only ) {
777
+ contacts = this.user_data[user].cache.get_contacts_ids()
778
+ } else {
779
+ contacts = this.user_data[user].cache.get_contacts()
780
+ }
781
+ return contacts
782
+ }
783
+
784
+
785
+ /**
786
+ *
787
+ * @param {string} id
788
+ * @param {string} method
789
+ * @param {any} params
790
+ * @returns {object}
791
+ */
792
+ async handle_rpc(method,params) {
793
+ //
794
+ let results = {
795
+ "error" : {"code": -32601, "message": "Method not found"}
796
+ }
797
+ //
798
+ switch (method) {
799
+ case "get-mail" : {
800
+ results = {
801
+ "result" : await this.gather_and_output_emails(params)
802
+ }
803
+ break;
804
+ }
805
+ case "store-mail" : {
806
+ let mail_list = params.params
807
+ if ( mail_list && Array.isArray(mail_list) && mail_list.length ) {
808
+ let mtype = params.mail_type
809
+ let user = params.user
810
+ this.user_data[user].cache.store_mails(mtype,mail_list)
811
+ await this.user_data[user].cache.add_list_to_storage(mtype,mail_list)
812
+ results = {
813
+ "result" : true
814
+ }
815
+ }
816
+ break;
817
+ }
818
+ case "remove-mail" : {
819
+ let mail_list = params.params
820
+ if ( mail_list && Array.isArray(mail_list) && mail_list.length ) {
821
+ let mtype = params.mail_type
822
+ let user = params.user
823
+ this.user_data[user].cache.remove_mails(mtype,mail_list)
824
+ results = {
825
+ "result" : true
826
+ }
827
+ }
828
+ break;
829
+ }
830
+ case "send-mail" : {
831
+ let mail_obj_list = params.params
832
+ if ( mail_obj_list && Array.isArray(mail_obj_list) && mail_obj_list.length ) {
833
+ let mtype = 'drafts'
834
+ let dst_type = 'sent'
835
+ let user = params.user
836
+ let mail_id_list = mail_obj_list.map(obj => { return obj.id })
837
+ await this.user_data[user].send_mails(mail_obj_list)
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
+ this.user_data[user].cache.move_mails(mtype,dst_type,mail_id_list)
841
+ // not clear if this next line needs to be called...
842
+ await this.user_data[user]?.mail_interface?.move_message_list(mail_id_list,dst_type)
843
+ results = {
844
+ "result" : true
845
+ }
846
+ }
847
+ break;
848
+ }
849
+
850
+ case "move-mail" : {
851
+ let mail_id_list = params.params
852
+ if ( mail_id_list && Array.isArray(mail_id_list) && mail_id_list.length ) {
853
+ let mtype = params.mail_type
854
+ let dst_type = params.to_mail_type
855
+ let user = params.user
856
+ if ( mtype === "drafts" ) {
857
+ this.user_data[user].cache.salvage_recipients_of_msgs(mtype,salvage_field,mail_id_list)
858
+ this.user_data[user].cache.drop_recipients_of_msgs(mail_id_list)
859
+ }
860
+ this.user_data[user].cache.move_mails(mtype,dst_type,mail_id_list)
861
+ await this.user_data[user]?.mail_interface?.move_message_list(mail_id_list,dst_type)
862
+ results = {
863
+ "result" : true
864
+ }
865
+ }
866
+ break;
867
+ }
868
+
869
+ case "store-draft" : {
870
+ let mail_object = params.params
871
+ if ( mail_object ) {
872
+ let mtype = params.mail_type
873
+ let user = params.user
874
+ this.user_data[user].cache.store_mails(mtype,[mail_object])
875
+ await this.user_data[user]?.mail_interface?.store_draft(mail_object)
876
+ results = {
877
+ "result" : true
878
+ }
879
+ }
880
+ break;
881
+ }
882
+ case "get-contacts" : {
883
+ results = {
884
+ "result" : await this.gather_and_output_contacts(params)
885
+ }
886
+ break;
887
+ }
888
+ case "store-contact" : {
889
+ let contact_object = params.params
890
+ if ( contact_object ) {
891
+ // let mtype = params.mail_type
892
+ let user = params.user
893
+ await this.user_data[user].cache.store_contacts([contact_object])
894
+ results = {
895
+ "result" : true
896
+ }
897
+ }
898
+ break;
899
+ }
900
+ case "remove-contact" : {
901
+ let contact_object = params.params
902
+ if ( contact_object ) {
903
+ // let mtype = params.mail_type
904
+ let user = params.user
905
+ this.user_data[user].cache.remove_contact(contact_object)
906
+ await this.user_data[user].cache.del_from_storage('contacts',contact_object.id)
907
+ results = {
908
+ "result" : true
909
+ }
910
+ }
911
+ break;
912
+ }
913
+
914
+ }
915
+
916
+ // ---- ---- ---- ---- ---- ----
917
+ // //
918
+ // ---- ---- ---- ---- ---- ----
919
+ return results
920
+ }
921
+
922
+
923
+ /**
924
+ *
925
+ * 'static.contact_message' -- a particular type of post that goes to the contact room of a concern (from front page)
926
+ * 'static.posts' --
927
+ * 'static.contacts' -- in particular a contact made by a copious-mail interface (a human page app)
928
+ *
929
+ * @param {string} table
930
+ * @param {string} method
931
+ * @param {object} params
932
+ */
933
+ async store_item(table,method,params) {
934
+ let results = {
935
+ "error" : {"code": -32601, "message": "Method not found"}
936
+ }
937
+
938
+ if ( method && params ) {
939
+ switch (table) {
940
+ case "contact_message" : { // this is mail deliver to a room that is the designated front-page contact room
941
+ let concern = params.concern
942
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
943
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
944
+ params.user = room_addr
945
+ return await this.handle_rpc("store-mail",params)
946
+ }
947
+ break;
948
+ }
949
+ case "messages" : { // part of mu-lite
950
+ let mtype = params.mail_type
951
+ if ( ['drafts','contacts'].includes(mtype) ) {
952
+ if ( mtype === 'drafts' ) {
953
+ return await this.handle_rpc("store-draft",params)
954
+ } else if ( mtype === 'contacts' ) { // a user contact v.s. the contact room for front page contacts
955
+ return await this.handle_rpc("store-mail",params)
956
+ }
957
+
958
+ } else {
959
+ return await this.handle_rpc("store-mail",params)
960
+ }
961
+ }
962
+ }
963
+
964
+ }
965
+
966
+ return results
967
+ }
968
+
969
+
970
+
971
+ /**
972
+ *
973
+ * 'static.contact_message' -- a particular type of post that goes to the contact room of a concern (from front page)
974
+ * 'static.posts' --
975
+ * 'static.contacts' -- in particular a contact made by a copious-mail interface (a human page app)
976
+ *
977
+ * @param {string} table
978
+ * @param {string} method
979
+ * @param {object} params
980
+ */
981
+ async get_items(table,id_only,method,params) {
982
+ let results = {
983
+ "error" : {"code": -32601, "message": "Method not found"}
984
+ }
985
+
986
+ if ( method && params ) {
987
+ params.id_only = id_only
988
+ switch (table) {
989
+ case "contact_message" : { // this is mail deliver to a room that is the designated front-page contact room
990
+ let concern = params.concern
991
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
992
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
993
+ params.user = room_addr
994
+ return await this.handle_rpc("get-mail",params)
995
+ }
996
+ break;
997
+ }
998
+ case "messages" : { // part of mu-lite
999
+ let mtype = params.mail_type
1000
+ if ( ['drafts','contacts'].includes(mtype) ) {
1001
+ if ( mtype === 'drafts' ) {
1002
+ return await this.handle_rpc("get-draft",params)
1003
+ } else if ( mtype === 'contacts' ) { // a user contact v.s. the contact room for front page contacts
1004
+ return await this.handle_rpc("get-contacts",params) // plural
1005
+ }
1006
+
1007
+ } else {
1008
+ return await this.handle_rpc("get-mail",params)
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ }
1014
+
1015
+ return results
1016
+ }
1017
+
1018
+
1019
+ /**
1020
+ *
1021
+ * @param {*} table
1022
+ * @param {*} params
1023
+ * @returns
1024
+ */
1025
+ async remove_items(table,params) {
1026
+ //
1027
+ let results = {
1028
+ "error" : {"code": -32601, "message": "Method not found"}
1029
+ }
1030
+
1031
+ let method = "remove-contact"
1032
+ method = "remove-mail"
1033
+
1034
+
1035
+ if ( method && params ) {
1036
+ switch (table) {
1037
+ case "contact_message" : {
1038
+ let concern = params.concern
1039
+ if ( !(concern) || this.contact_rooms.includes(concern) ) {
1040
+ let room_addr = concern ? `${concern}-contacts` : "copious-contacts"
1041
+ params.user = room_addr
1042
+ return await this.handle_rpc("remove-contact",params)
1043
+ }
1044
+ break;
1045
+ }
1046
+ case "messages" : {
1047
+ let mtype = params.mail_type
1048
+ if ( ['contacts'].includes(mtype) ) {
1049
+ return await this.handle_rpc("remove-contact",params)
1050
+ } else {
1051
+ return await this.handle_rpc("remove-contact",params)
1052
+ }
1053
+ }
1054
+ }
1055
+ }
1056
+
1057
+ return results
1058
+ }
1059
+
1060
+ //
1061
+ /**
1062
+ *
1063
+ * @param {string} method
1064
+ * @param {any} params
1065
+ * @returns {boolean}
1066
+ */
1067
+ handle_rpc_notify(method,params) {
1068
+ return true
1069
+ }
1070
+
1071
+
1072
+ /**
1073
+ *
1074
+ * @returns {object|string}
1075
+ */
1076
+ sendable_proc_data() { // should be an update on emails, etc.
1077
+ return (new Date()).toLocaleString()
1078
+ }
1079
+
1080
+
1081
+ /**
1082
+ *
1083
+ * @returns {object|boolean}
1084
+ */
1085
+ async ws_handle_user_update_req(mail_req) {
1086
+ let sendable = this.websocket_test_data
1087
+ let op_message = {
1088
+ "op" : "all-updates",
1089
+ "data" : sendable
1090
+ }
1091
+ return op_message
1092
+ }
1093
+
1094
+ /**
1095
+ *
1096
+ * @returns {object|boolean}
1097
+ */
1098
+ async ws_data_updates() {
1099
+ //
1100
+ if ( !(this.messages_sent) ) {
1101
+ let sendable = this.websocket_test_data
1102
+ let op_message = {
1103
+ "op" : "all-updates",
1104
+ "data" : sendable
1105
+ }
1106
+ return op_message
1107
+ }
1108
+ //
1109
+ return false
1110
+ }
1111
+
1112
+ /**
1113
+ *
1114
+ * @param {boolean} sent
1115
+ */
1116
+ update_messages_sent(sent) {
1117
+ this.messages_sent = sent
1118
+ }
1119
+
1120
+
1121
+ /**
1122
+ *
1123
+ * @param {object} ext_repo_conf
1124
+ */
1125
+ file_upload_bridge(ext_repo_conf) {
1126
+ // for upload operations ... using the file uploading from the cit server
1127
+ }
1128
+
1129
+
1130
+
1131
+
1132
+ /**
1133
+ *
1134
+ * @param {object} obj
1135
+ * @returns
1136
+ */
1137
+ get_asset_file(obj) {
1138
+ let file_name = obj.file
1139
+ obj.data = "this is a test: " + file_name
1140
+ return true
1141
+ }
1142
+
1143
+ /**
1144
+ *
1145
+ * @param {object} obj
1146
+ * @
1147
+ *
1148
+ * returns
1149
+ */
1150
+ get_app_file(obj) {
1151
+ let file_name = obj.file
1152
+ obj.data = "this is a test: " + file_name
1153
+ return true
1154
+ }
1155
+
1156
+
1157
+ async add_files(data) {
1158
+ //
1159
+ }
1160
+
1161
+ async update_files(data) {
1162
+ //
1163
+ }
1164
+
1165
+ async get_active_user(id) {
1166
+
1167
+ }
1168
+
1169
+ async add_active_user(value) {
1170
+ let id = value.id
1171
+ }
1172
+
1173
+ }
1174
+
1175
+
1176
+
1177
+ module.exports = MailRepoBridgeOps