2 * Handles functions related to yellow sticky notes.
4 * Copyright (c) 2007-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
28 #include <libcitadel.h>
31 #include "citserver.h"
37 #include "ctdl_module.h"
41 * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure
43 void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
44 void *content, char *cbtype, char *cbcharset, size_t length,
45 char *encoding, char *cbid, void *cbuserdata)
47 struct vnote **v = (struct vnote **) cbuserdata;
49 if (!strcasecmp(cbtype, "text/vnote")) {
51 syslog(LOG_DEBUG, "Part %s contains a vNote! Loading...\n", partnum);
55 *v = vnote_new_from_str(content);
61 * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes
62 * and modern vNote format notes) and does its best to learn the subject (summary)
63 * and EUID (uid) of the note for Citadel's own nefarious purposes.
65 int serv_notes_beforesave(struct CtdlMessage *msg, recptypes *recp)
70 struct vnote *v = NULL;
72 /* First determine if this room has the "notes" view set */
74 if (CC->room.QRdefaultview != VIEW_NOTES) {
75 return(0); /* not notes; do nothing */
78 /* It must be an RFC822 message! */
79 if (msg->cm_format_type != 4) {
80 return(0); /* You tried to save a non-RFC822 message! */
84 * If we are in a "notes" view room, and the client has sent an RFC822
85 * message containing an X-KOrg-Note-Id: field (Aethera does this, as
86 * do some Kolab clients) then set both the Subject and the Exclusive ID
87 * of the message to that. It's going to be a UUID so we want to replace
88 * any existing message containing that UUID.
91 p = msg->cm_fields[eMesageText];
92 a = msg->cm_lengths[eMesageText];
94 if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { /* Found it */
95 safestrncpy(uuid, p + 16, sizeof(uuid));
96 for (i = 0; uuid[i]; ++i) {
97 if ( (uuid[i] == '\r') || (uuid[i] == '\n') ) {
103 syslog(LOG_DEBUG, "UUID of note is: %s\n", uuid);
104 if (!IsEmptyStr(uuid)) {
105 CM_SetField(msg, eExclusiveID, uuid, strlen(uuid));
107 CM_CopyField(msg, eMsgSubject, eExclusiveID);
113 /* Modern clients are using vNote format. Check for one... */
115 mime_parser(CM_RANGE(msg, eMesageText),
116 *notes_extract_vnote,
118 &v, /* user data ptr - put the vnote here */
122 if (v == NULL) return(0); /* no vNotes were found in this message */
124 /* Set the message EUID to the vNote UID */
126 if ((v->uid) && (!IsEmptyStr(v->uid))) {
127 syslog(LOG_DEBUG, "UID of vNote is: %s\n", v->uid);
128 CM_SetField(msg, eExclusiveID, v->uid, strlen(v->uid));
131 /* Set the message Subject to the vNote Summary */
133 if ((v->summary) && (!IsEmptyStr(v->summary))) {
134 CM_SetField(msg, eMsgSubject, v->summary, strlen(v->summary));
136 if (msg->cm_lengths[eMsgSubject] > 72) {
137 strcpy(&msg->cm_fields[eMsgSubject][68], "...");
138 CM_CutFieldAt(msg, eMsgSubject, 72);
148 CTDL_MODULE_INIT(notes)
152 CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE);
155 /* return our module name for the log */