Adjust handling of seen events, add debug functions to retrieve & set seen stamps
[citadel.git] / citadel / msgbase.c
index 4c1bd70ed2bdb2fedc8c1579e5c3a0f313909798..4d1881c6ba081e67968d2ca8f2d02d48506d4dbf 100644 (file)
@@ -3061,7 +3061,8 @@ void flood_protect_quickie_message(const char *from,
        StrBuf *guid;
        char timestamp[64];
        long tslen;
-       time_t tsday = NOW / (8*60*60); /* just care for a day... */
+       static const time_t tsday = (8*60*60); /* just care for a day... */
+       time_t seenstamp;
 
        tslen = snprintf(timestamp, sizeof(timestamp), "%ld", tsday);
        MD5Init(&md5context);
@@ -3080,29 +3081,35 @@ void flood_protect_quickie_message(const char *from,
        if (StrLength(guid) > 40)
                StrBufCutAt(guid, 40, NULL);
 
-       if (CheckIfAlreadySeen("FPAideMessage",
-                              guid,
-                              NOW,
-                              tsday,
-                              eUpdate,
-                              ccid,
-                              ioid)!= 0)
+       seenstamp = CheckIfAlreadySeen("FPAideMessage",
+                                      guid,
+                                      NOW,
+                                      tsday,
+                                      eUpdate,
+                                      ccid,
+                                      ioid);
+       if (seenstamp < tsday)
        {
                FreeStrBuf(&guid);
                /* yes, we did. flood protection kicks in. */
                syslog(LOG_DEBUG,
-                      "not sending message again\n");
+                      "not sending message again - %ld < %ld \n", seenstamp, tsday);
                return;
        }
-       FreeStrBuf(&guid);
-       /* no, this message isn't sent recently; go ahead. */
-       quickie_message(from,
-                       fromaddr,
-                       to,
-                       room,
-                       text, 
-                       format_type,
-                       subject);
+       else
+       {
+               syslog(LOG_DEBUG,
+                      "sending message. %ld >= %ld", seenstamp, tsday);
+               FreeStrBuf(&guid);
+               /* no, this message isn't sent recently; go ahead. */
+               quickie_message(from,
+                               fromaddr,
+                               to,
+                               room,
+                               text, 
+                               format_type,
+                               subject);
+       }
 }