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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
29 #include <sys/types.h>
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
45 #include <libcitadel.h>
48 #include "citserver.h"
55 #include "ctdl_module.h"
59 * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure
61 void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
62 void *content, char *cbtype, char *cbcharset, size_t length,
63 char *encoding, char *cbid, void *cbuserdata)
65 struct vnote **v = (struct vnote **) cbuserdata;
67 if (!strcasecmp(cbtype, "text/vnote")) {
69 syslog(LOG_DEBUG, "Part %s contains a vNote! Loading...\n", partnum);
73 *v = vnote_new_from_str(content);
79 * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes
80 * and modern vNote format notes) and does its best to learn the subject (summary)
81 * and EUID (uid) of the note for Citadel's own nefarious purposes.
83 int serv_notes_beforesave(struct CtdlMessage *msg, recptypes *recp)
88 struct vnote *v = NULL;
90 /* First determine if this room has the "notes" view set */
92 if (CC->room.QRdefaultview != VIEW_NOTES) {
93 return(0); /* not notes; do nothing */
96 /* It must be an RFC822 message! */
97 if (msg->cm_format_type != 4) {
98 return(0); /* You tried to save a non-RFC822 message! */
102 * If we are in a "notes" view room, and the client has sent an RFC822
103 * message containing an X-KOrg-Note-Id: field (Aethera does this, as
104 * do some Kolab clients) then set both the Subject and the Exclusive ID
105 * of the message to that. It's going to be a UUID so we want to replace
106 * any existing message containing that UUID.
109 p = msg->cm_fields[eMesageText];
110 a = msg->cm_lengths[eMesageText];
112 if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { /* Found it */
113 safestrncpy(uuid, p + 16, sizeof(uuid));
114 for (i = 0; uuid[i]; ++i) {
115 if ( (uuid[i] == '\r') || (uuid[i] == '\n') ) {
121 syslog(LOG_DEBUG, "UUID of note is: %s\n", uuid);
122 if (!IsEmptyStr(uuid)) {
123 CM_SetField(msg, eExclusiveID, uuid, strlen(uuid));
125 CM_CopyField(msg, eMsgSubject, eExclusiveID);
131 /* Modern clients are using vNote format. Check for one... */
133 mime_parser(CM_RANGE(msg, eMesageText),
134 *notes_extract_vnote,
136 &v, /* user data ptr - put the vnote here */
140 if (v == NULL) return(0); /* no vNotes were found in this message */
142 /* Set the message EUID to the vNote UID */
144 if ((v->uid) && (!IsEmptyStr(v->uid))) {
145 syslog(LOG_DEBUG, "UID of vNote is: %s\n", v->uid);
146 CM_SetField(msg, eExclusiveID, v->uid, strlen(v->uid));
149 /* Set the message Subject to the vNote Summary */
151 if ((v->summary) && (!IsEmptyStr(v->summary))) {
152 CM_SetField(msg, eMsgSubject, v->summary, strlen(v->summary));
154 if (msg->cm_lengths[eMsgSubject] > 72) {
155 strcpy(&msg->cm_fields[eMsgSubject][68], "...");
156 CM_CutFieldAt(msg, eMsgSubject, 72);
166 CTDL_MODULE_INIT(notes)
170 CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE);
173 /* return our module name for the log */