1 // Handles functions related to yellow sticky notes.
3 // Copyright (c) 2007-2024 by the citadel.org team
4 // This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License v3.
6 #include "../../sysdep.h"
14 #include <sys/types.h>
19 #include <libcitadel.h>
20 #include "../../citadel_defs.h"
21 #include "../../server.h"
22 #include "../../citserver.h"
23 #include "../../support.h"
24 #include "../../config.h"
25 #include "../../user_ops.h"
26 #include "../../database.h"
27 #include "../../msgbase.h"
28 #include "../../ctdl_module.h"
31 // Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure
32 void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
33 void *content, char *cbtype, char *cbcharset, size_t length,
34 char *encoding, char *cbid, void *cbuserdata)
36 struct vnote **v = (struct vnote **) cbuserdata;
38 if (!strcasecmp(cbtype, "text/vnote")) {
39 syslog(LOG_DEBUG, "Part %s contains a vNote! Loading...\n", partnum);
43 *v = vnote_new_from_str(content);
48 // Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes
49 // and modern vNote format notes) and does its best to learn the subject (summary)
50 // and EUID (uid) of the note for Citadel's own nefarious purposes.
51 int serv_notes_beforesave(struct CtdlMessage *msg, struct recptypes *recp) {
55 struct vnote *v = NULL;
57 // First determine if this room has the "notes" view set
59 if (CC->room.QRdefaultview != VIEW_NOTES) {
60 return(0); // not notes; do nothing
63 // It must be an RFC822 message!
64 if (msg->cm_format_type != 4) {
65 return(0); // You tried to save a non-RFC822 message!
68 // If we are in a "notes" view room, and the client has sent an RFC822
69 // message containing an X-KOrg-Note-Id: field (Aethera does this, as
70 // do some Kolab clients) then set both the Subject and the Exclusive ID
71 // of the message to that. It's going to be a UUID so we want to replace
72 // any existing message containing that UUID.
74 p = msg->cm_fields[eMessageText];
75 a = msg->cm_lengths[eMessageText];
77 if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { // Found it
78 safestrncpy(uuid, p + 16, sizeof(uuid));
79 for (i = 0; uuid[i]; ++i) {
80 if ( (uuid[i] == '\r') || (uuid[i] == '\n') ) {
86 syslog(LOG_DEBUG, "UUID of note is: %s\n", uuid);
87 if (!IsEmptyStr(uuid)) {
88 CM_SetField(msg, eExclusiveID, uuid);
89 CM_CopyField(msg, eMsgSubject, eExclusiveID);
95 // Modern clients are using vNote format. Check for one...
97 mime_parser(CM_RANGE(msg, eMessageText),
100 &v, // user data ptr - put the vnote here
104 if (v == NULL) return(0); // no vNotes were found in this message
106 // Set the message EUID to the vNote UID
108 if ((v->uid) && (!IsEmptyStr(v->uid))) {
109 syslog(LOG_DEBUG, "UID of vNote is: %s\n", v->uid);
110 CM_SetField(msg, eExclusiveID, v->uid);
113 // Set the message Subject to the vNote Summary
115 if ((v->summary) && (!IsEmptyStr(v->summary))) {
116 CM_SetField(msg, eMsgSubject, v->summary);
118 if (msg->cm_lengths[eMsgSubject] > 72) {
119 strcpy(&msg->cm_fields[eMsgSubject][68], "...");
120 CM_CutFieldAt(msg, eMsgSubject, 72);
130 // Initialization function, called from modules_init.c
131 char *ctdl_module_init_notes(void) {
133 CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE);
136 // return our module name for the log