SEEN-Database: refactor database interface for remembering whether we already aggrega...
[citadel.git] / citadel / msgbase.c
index 0b8e8ba9194912f4f63c707949b1f8d6f00e3dbf..5c10578c0160e711ab4464789833815bcda8bf91 100644 (file)
@@ -116,6 +116,15 @@ char *msgkeys[] = {
        NULL    /* Z */
 };
 
+void CtdlMsgSetCM_Fields(struct CtdlMessage *Msg, const char which, const char *buf, long length)
+{
+       if (Msg->cm_fields[which] != NULL)
+               free (Msg->cm_fields[which]);
+       Msg->cm_fields[which] = malloc(length + 1);
+       memcpy(Msg->cm_fields[which], buf, length);
+       Msg->cm_fields[which][length] = '\0';
+}
+
 /*
  * This function is self explanatory.
  * (What can I say, I'm in a weird mood today...)
@@ -1138,7 +1147,7 @@ void mime_download(char *name, char *filename, char *partnum, char *disp,
                        return;
                }
        
-               rv = fwrite(content, length, 1, CC->download_fp);
+               rv = fwrite(content, length, 1, CCC->download_fp);
                if (rv <= 0) {
                        MSG_syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n",
                                   strerror(errno));
@@ -1204,6 +1213,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body)
        MSG_syslog(LOG_DEBUG, "CtdlFetchMessage(%ld, %d)\n", msgnum, with_body);
        dmsgtext = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
        if (dmsgtext == NULL) {
+               MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Failed!\n", msgnum, with_body);
                return NULL;
        }
        mptr = dmsgtext->ptr;
@@ -3596,18 +3606,18 @@ void flood_protect_quickie_message(const char *from,
                                   const char *subject,
                                   int nCriterions,
                                   const char **CritStr,
-                                  long *CritStrLen)
+                                  long *CritStrLen,
+                                  long ccid,
+                                  long ioid,
+                                  time_t NOW)
 {
        int i;
-       struct UseTable ut;
        u_char rawdigest[MD5_DIGEST_LEN];
        struct MD5Context md5context;
        StrBuf *guid;
-       struct cdbdata *cdbut;
        char timestamp[64];
        long tslen;
-       time_t ts = time(NULL);
-       time_t tsday = ts / (8*60*60); /* just care for a day... */
+       time_t tsday = NOW / (8*60*60); /* just care for a day... */
 
        tslen = snprintf(timestamp, sizeof(timestamp), "%ld", tsday);
        MD5Init(&md5context);
@@ -3625,27 +3635,22 @@ void flood_protect_quickie_message(const char *from,
        StrBufAppendBufPlain(guid, HKEY("_fldpt"), 0);
        if (StrLength(guid) > 40)
                StrBufCutAt(guid, 40, NULL);
-       /* Find out if we've already sent a similar message */
-       memcpy(ut.ut_msgid, SKEY(guid));
-       ut.ut_timestamp = ts;
 
-       cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid));
-
-       if (cdbut != NULL) {
+       if (CheckIfAlreadySeen("FPAideMessage",
+                              guid,
+                              NOW,
+                              tsday,
+                              eUpdate,
+                              ccid,
+                              ioid)!= 0)
+       {
+               FreeStrBuf(&guid);
                /* yes, we did. flood protection kicks in. */
                syslog(LOG_DEBUG,
                       "not sending message again\n");
-               cdb_free(cdbut);
+               return;
        }
-
-       /* rewrite the record anyway, to update the timestamp */
-       cdb_store(CDB_USETABLE,
-                 SKEY(guid),
-                 &ut, sizeof(struct UseTable) );
-       
        FreeStrBuf(&guid);
-
-       if (cdbut != NULL) return;
        /* no, this message isn't sent recently; go ahead. */
        quickie_message(from,
                        fromaddr,