]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/notes/serv_notes.c
more places where we can use cm_lengths;
[citadel.git] / citadel / modules / notes / serv_notes.c
index 56c1e6ee94690a9260bfcfc8753911001bf54008..a250c8ccd63a652d7a317d1f33ad99ee7256a1c5 100644 (file)
@@ -1,8 +1,21 @@
 /*
- * $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"
@@ -35,9 +48,7 @@
 #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"
 
  */
 void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
                   void *content, char *cbtype, char *cbcharset, size_t length,
-                  char *encoding, void *cbuserdata)
+                  char *encoding, char *cbid, void *cbuserdata)
 {
        struct vnote **v = (struct vnote **) cbuserdata;
 
        if (!strcasecmp(cbtype, "text/vnote")) {
 
-               CtdlLogPrintf(CTDL_DEBUG, "Part %s contains a vNote!  Loading...\n", partnum);
+               syslog(LOG_DEBUG, "Part %s contains a vNote!  Loading...\n", partnum);
                if (*v != NULL) {
                        vnote_free(*v);
                }
@@ -69,7 +80,7 @@ void notes_extract_vnote(char *name, char *filename, char *partnum, char *disp,
  * 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, recptypes *recp)
 {
        char *p;
        int a, i;
@@ -95,8 +106,8 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
         * 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));
@@ -107,18 +118,11 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
                                }
                        }
 
-                       CtdlLogPrintf(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++;
@@ -126,7 +130,7 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
 
        /* Modern clients are using vNote format.  Check for one... */
 
-       mime_parser(msg->cm_fields['M'],
+       mime_parser(msg->cm_fields[eMesageText],
                NULL,
                *notes_extract_vnote,
                NULL, NULL,
@@ -138,23 +142,19 @@ int serv_notes_beforesave(struct CtdlMessage *msg)
 
        /* Set the message EUID to the vNote UID */
 
-       if (v->uid) if (!IsEmptyStr(v->uid)) {
-               CtdlLogPrintf(9, "UID of vNote is: %s\n", v->uid);
-               if (msg->cm_fields['E'] != NULL) {
-                       free(msg->cm_fields['E']);
-               }
-               msg->cm_fields['E'] = strdup(v->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) if (!IsEmptyStr(v->summary)) {
-               if (msg->cm_fields['U'] != NULL) {
-                       free(msg->cm_fields['U']);
-               }
-               msg->cm_fields['U'] = strdup(v->summary);
-               if (strlen(msg->cm_fields['U']) > 72) {
-                       strcpy(&msg->cm_fields['U'][68], "...");
+       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);
                }
        }
 
@@ -171,6 +171,6 @@ CTDL_MODULE_INIT(notes)
                CtdlRegisterMessageHook(serv_notes_beforesave, EVT_BEFORESAVE);
        }
        
-       /* return our Subversion id for the Log */
-       return "$Id$";
+       /* return our module name for the log */
+       return "notes";
 }