X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fnotes%2Fserv_notes.c;h=4ae8ac077a90a2863e899c42edd2eda8771131d6;hb=882ff5a53c3b4e440520a073cf07dc60b2671876;hp=242fa3e5a358cf794e73247a321a7e8cff2194de;hpb=b425dda0a48b4a3e24a9f22d25e864d42679feee;p=citadel.git diff --git a/citadel/modules/notes/serv_notes.c b/citadel/modules/notes/serv_notes.c index 242fa3e5a..4ae8ac077 100644 --- a/citadel/modules/notes/serv_notes.c +++ b/citadel/modules/notes/serv_notes.c @@ -1,8 +1,15 @@ /* - * $Id$ - * * Handles functions related to yellow sticky notes. * + * Copyright (c) 2007-2012 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "sysdep.h" @@ -14,49 +21,53 @@ #include #include #include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - +#include #include #include #include +#include #include "citadel.h" #include "server.h" #include "citserver.h" #include "support.h" #include "config.h" -#include "room_ops.h" #include "user_ops.h" -#include "policy.h" #include "database.h" #include "msgbase.h" -#include "tools.h" - #include "ctdl_module.h" +/* + * Callback function for serv_notes_beforesave() hunts for a vNote in the MIME structure + */ +void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp, + void *content, char *cbtype, char *cbcharset, size_t length, + char *encoding, char *cbid, void *cbuserdata) +{ + struct vnote **v = (struct vnote **) cbuserdata; + + if (!strcasecmp(cbtype, "text/vnote")) { + + syslog(LOG_DEBUG, "Part %s contains a vNote! Loading...\n", partnum); + if (*v != NULL) { + vnote_free(*v); + } + *v = vnote_new_from_str(content); + } +} + /* - * If we are in a "notes" view room, and the client has sent an RFC822 - * message containing an X-KOrg-Note-Id: field (Aethera does this, as - * do some Kolab clients) then set both the Subject and the Exclusive ID - * of the message to that. It's going to be a UUID so we want to replace - * any existing message containing that UUID. + * Before-save hook searches for two different types of notes (legacy Kolab/Aethera notes + * and modern vNote format notes) and does its best to learn the subject (summary) + * and EUID (uid) of the note for Citadel's own nefarious purposes. */ -int serv_notes_beforesave(struct CtdlMessage *msg) +int serv_notes_beforesave(struct CtdlMessage *msg, struct recptypes *recp) { char *p; int a, i; - char uuid[SIZ]; + char uuid[512]; + struct vnote *v = NULL; /* First determine if this room has the "notes" view set */ @@ -69,36 +80,66 @@ int serv_notes_beforesave(struct CtdlMessage *msg) return(0); /* You tried to save a non-RFC822 message! */ } - /* Find the X-KOrg-Note-Id: header */ + /* + * If we are in a "notes" view room, and the client has sent an RFC822 + * message containing an X-KOrg-Note-Id: field (Aethera does this, as + * do some Kolab clients) then set both the Subject and the Exclusive ID + * of the message to that. It's going to be a UUID so we want to replace + * any existing message containing that UUID. + */ strcpy(uuid, ""); - p = msg->cm_fields['M']; - a = strlen(p); + p = msg->cm_fields[eMesageText]; + a = msg->cm_lengths[eMesageText]; while (--a > 0) { if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { /* Found it */ safestrncpy(uuid, p + 16, sizeof(uuid)); - for (i = 0; !IsEmptyStr(&uuid[i]); ++i) { + for (i = 0; uuid[i]; ++i) { if ( (uuid[i] == '\r') || (uuid[i] == '\n') ) { uuid[i] = 0; break; } } - lprintf(9, "UUID of note is: %s\n", uuid); + syslog(LOG_DEBUG, "UUID of note is: %s\n", uuid); if (!IsEmptyStr(uuid)) { + CM_SetField(msg, eExclusiveID, uuid, strlen(uuid)); - if (msg->cm_fields['E'] != NULL) { - free(msg->cm_fields['E']); - } - msg->cm_fields['E'] = strdup(uuid); - - if (msg->cm_fields['U'] != NULL) { - free(msg->cm_fields['U']); - } - msg->cm_fields['U'] = strdup(uuid); + CM_CopyField(msg, eMsgSubject, eExclusiveID); } } p++; } + + /* Modern clients are using vNote format. Check for one... */ + + mime_parser(CM_RANGE(msg, eMesageText), + *notes_extract_vnote, + NULL, NULL, + &v, /* user data ptr - put the vnote here */ + 0 + ); + + if (v == NULL) return(0); /* no vNotes were found in this message */ + + /* Set the message EUID to the vNote UID */ + + if ((v->uid) && (!IsEmptyStr(v->uid))) { + syslog(LOG_DEBUG, "UID of vNote is: %s\n", v->uid); + CM_SetField(msg, eExclusiveID, v->uid, strlen(v->uid)); + } + + /* Set the message Subject to the vNote Summary */ + + if ((v->summary) && (!IsEmptyStr(v->summary))) { + CM_SetField(msg, eMsgSubject, v->summary, strlen(v->summary)); + + if (msg->cm_lengths[eMsgSubject] > 72) { + strcpy(&msg->cm_fields[eMsgSubject][68], "..."); + CM_CutFieldAt(msg, eMsgSubject, 72); + } + } + + vnote_free(v); return(0); } @@ -106,8 +147,11 @@ int serv_notes_beforesave(struct CtdlMessage *msg) CTDL_MODULE_INIT(notes) { - CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE); - - /* return our Subversion id for the Log */ - return "$Id$"; + if (!threading) + { + CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE); + } + + /* return our module name for the log */ + return "notes"; }