]> code.citadel.org Git - citadel.git/commitdiff
CtdlForEachMessage() now accepts regular expressions when
authorArt Cancro <ajc@citadel.org>
Sat, 17 Mar 2007 03:41:09 +0000 (03:41 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 17 Mar 2007 03:41:09 +0000 (03:41 +0000)
searching for messages with a specific MIME type.  This was necessary
for the text/x-vcard to text/vcard transition.

citadel/msgbase.c
citadel/serv_calendar.c
citadel/serv_vcard.c

index 2ec3668c0197f1778d6d2932b9b913b413367926..b17e920405879c5f78d47ee695e43f3130ce482b 100644 (file)
@@ -524,6 +524,12 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
        int printed_lastold = 0;
        int num_search_msgs = 0;
        long *search_msgs = NULL;
+       regex_t re;
+       regmatch_t pm;
+
+       if (content_type) if (strlen(content_type) > 0) {
+               regcomp(&re, content_type, 0);
+       }
 
        /* Learn about the user and room in question */
        getuser(&CC->user, CC->curr_user);
@@ -562,7 +568,8 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                         */
                        GetMetaData(&smi, msglist[a]);
 
-                       if (strcasecmp(smi.meta_content_type, content_type)) {
+                       /* if (strcasecmp(smi.meta_content_type, content_type)) { old non-regex way */
+                       if (regexec(&re, smi.meta_content_type, 1, &pm, 0) != 0) {
                                msglist[a] = 0L;
                        }
                }
index 758f9b0ce0468fb25286ad6a7c1da7757b158755..ecad5e88f9b7c0d44535e36e41d44bbcf9d8156b 100644 (file)
@@ -971,7 +971,7 @@ void ical_hunt_for_conflicts(icalcomponent *cal) {
 
        cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
 
-       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/[Cc][Aa][Ll][Ee][Nn][Dd][Aa][Rr]$",
                NULL,
                ical_hunt_for_conflicts_backend,
                (void *) cal
@@ -1276,7 +1276,7 @@ void ical_freebusy(char *who) {
 
        /* Add busy time from events */
        lprintf(CTDL_DEBUG, "Adding busy time from events\n");
-       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/[Cc][Aa][Ll][Ee][Nn][Dd][Aa][Rr]$",
                NULL, ical_freebusy_backend, (void *)fb
        );
 
@@ -1417,7 +1417,7 @@ void ical_getics(void)
 
        /* Now go through the room encapsulating all calendar items. */
        CtdlForEachMessage(MSGS_ALL, 0, NULL,
-               "text/calendar",
+               "^[Tt][Ee][Xx][Tt]/[Cc][Aa][Ll][Ee][Nn][Dd][Aa][Rr]$",
                NULL,
                ical_getics_backend,
                (void *) encaps
index ed31981b3ec479edb3001597cd9327b325ea464b..8908393e43a52b4750f8495fa16dc9388d6ee322 100644 (file)
@@ -190,7 +190,7 @@ void cmd_igab(char *argbuf) {
        CtdlDirectoryInit();
 
        /* We want *all* vCards in this room */
-       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
                NULL, vcard_add_to_directory, NULL);
 
        getroom(&CC->room, hold_rm);    /* return to saved room */
@@ -548,7 +548,7 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
 
        /* We want the last (and probably only) vcard in this room */
        VCmsgnum = (-1);
-       CtdlForEachMessage(MSGS_LAST, 1, NULL, "text/x-vcard",
+       CtdlForEachMessage(MSGS_LAST, 1, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$",
                NULL, vcard_gu_backend, (void *)&VCmsgnum );
        getroom(&CC->room, hold_rm);    /* return to saved room */
 
@@ -1101,7 +1101,7 @@ void store_this_ha(struct addresses_to_be_filed *aptr) {
 
        /* First remove any addresses we already have in the address book */
        usergoto(aptr->roomname, 0, 0, NULL, NULL);
-       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/x-vcard", NULL,
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "^[Tt][Ee][Xx][Tt]/.*[Vv][Cc][Aa][Rr][Dd]$", NULL,
                strip_addresses_already_have, aptr->collected_addresses);
 
        if (strlen(aptr->collected_addresses) > 0)