4 * Handles functions related to yellow sticky notes.
6 * Copyright (c) 2007-2009 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
33 #if TIME_WITH_SYS_TIME
34 # include <sys/time.h>
38 # include <sys/time.h>
47 #include <libcitadel.h>
50 #include "citserver.h"
59 #include "ctdl_module.h"
63 * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure
65 void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
66 void *content, char *cbtype, char *cbcharset, size_t length,
67 char *encoding, char *cbid, void *cbuserdata)
69 struct vnote **v = (struct vnote **) cbuserdata;
71 if (!strcasecmp(cbtype, "text/vnote")) {
73 CtdlLogPrintf(CTDL_DEBUG, "Part %s contains a vNote! Loading...\n", partnum);
77 *v = vnote_new_from_str(content);
83 * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes
84 * and modern vNote format notes) and does its best to learn the subject (summary)
85 * and EUID (uid) of the note for Citadel's own nefarious purposes.
87 int serv_notes_beforesave(struct CtdlMessage *msg)
92 struct vnote *v = NULL;
94 /* First determine if this room has the "notes" view set */
96 if (CC->room.QRdefaultview != VIEW_NOTES) {
97 return(0); /* not notes; do nothing */
100 /* It must be an RFC822 message! */
101 if (msg->cm_format_type != 4) {
102 return(0); /* You tried to save a non-RFC822 message! */
106 * If we are in a "notes" view room, and the client has sent an RFC822
107 * message containing an X-KOrg-Note-Id: field (Aethera does this, as
108 * do some Kolab clients) then set both the Subject and the Exclusive ID
109 * of the message to that. It's going to be a UUID so we want to replace
110 * any existing message containing that UUID.
113 p = msg->cm_fields['M'];
116 if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { /* Found it */
117 safestrncpy(uuid, p + 16, sizeof(uuid));
118 for (i = 0; uuid[i]; ++i) {
119 if ( (uuid[i] == '\r') || (uuid[i] == '\n') ) {
125 CtdlLogPrintf(9, "UUID of note is: %s\n", uuid);
126 if (!IsEmptyStr(uuid)) {
128 if (msg->cm_fields['E'] != NULL) {
129 free(msg->cm_fields['E']);
131 msg->cm_fields['E'] = strdup(uuid);
133 if (msg->cm_fields['U'] != NULL) {
134 free(msg->cm_fields['U']);
136 msg->cm_fields['U'] = strdup(uuid);
142 /* Modern clients are using vNote format. Check for one... */
144 mime_parser(msg->cm_fields['M'],
146 *notes_extract_vnote,
148 &v, /* user data ptr - put the vnote here */
152 if (v == NULL) return(0); /* no vNotes were found in this message */
154 /* Set the message EUID to the vNote UID */
156 if (v->uid) if (!IsEmptyStr(v->uid)) {
157 CtdlLogPrintf(9, "UID of vNote is: %s\n", v->uid);
158 if (msg->cm_fields['E'] != NULL) {
159 free(msg->cm_fields['E']);
161 msg->cm_fields['E'] = strdup(v->uid);
164 /* Set the message Subject to the vNote Summary */
166 if (v->summary) if (!IsEmptyStr(v->summary)) {
167 if (msg->cm_fields['U'] != NULL) {
168 free(msg->cm_fields['U']);
170 msg->cm_fields['U'] = strdup(v->summary);
171 if (strlen(msg->cm_fields['U']) > 72) {
172 strcpy(&msg->cm_fields['U'][68], "...");
182 CTDL_MODULE_INIT(notes)
186 CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE);
189 /* return our Subversion id for the Log */