New config option: set smtp_advertise_starttls to nonzero to advertise STARTTLS in...
authorArt Cancro <ajc@citadel.org>
Sat, 20 Jan 2024 16:01:04 +0000 (11:01 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 20 Jan 2024 16:01:04 +0000 (11:01 -0500)
citadel/server/config.c
citadel/server/modules/calendar/calendar_report.c
citadel/server/modules/smtp/serv_smtp.c

index 44b1c3d97f6e667578216ddc142fcfbb250a52a6..7932ca81da570bd39034602cbf6e0340c6556485 100644 (file)
@@ -311,7 +311,6 @@ void CtdlSetConfigStr(char *key, char *value) {
        Put(ctdlconfig, key, key_len, strdup(value), NULL);
 
        // Also write it to the config database
-
        int dbv_size = key_len + value_len + 2;
        char *dbv = malloc(dbv_size);
        strcpy(dbv, key);
@@ -372,7 +371,7 @@ char *CtdlGetConfigStr(char *key) {
 
        // Then look in the database.
        cdb = cdb_fetch(CDB_CONFIG, key, key_len);
-       if (cdb.ptr == NULL) {  // nope, not there either.
+       if (cdb.ptr == NULL) {                          // nope, not there either.
                return(NULL);
        }
 
index a7fb8ba1d3094032a85df3365612257ad67573b3..c9d7eb19967d29da9ae67eb7ee3b18f980585cbd 100644 (file)
 #include "serv_calendar.h"
 
 
-// CtdlForEachMessage back end
+// CtdlForEachMessage callback for calendar_report()
 void calendar_report_backend(long msgnum, void *data) {
-       syslog(LOG_DEBUG, "%ld", msgnum);
+       struct CtdlMessage *msg = NULL;
+       struct ical_respond_data ird;
+
+       syslog(LOG_DEBUG, "calendar_report: calendar_report_backend(%ld)", msgnum);
+
+       // Look for the calendar event...
+       msg = CtdlFetchMessage(msgnum, 1);
+       if (msg == NULL) return;
+       memset(&ird, 0, sizeof ird);
+       strcpy(ird.desired_partnum, "_HUNT_");
+       mime_parser(
+               CM_RANGE(msg, eMessageText),
+               *ical_locate_part,              // This callback function extracts a vcalendar item from the message.
+               NULL,
+               NULL,
+               (void *) &ird,                  // Give it this place to put the vcalendar object.
+               0
+       );
+       CM_Free(msg);
+       if (ird.cal == NULL) return;            // If there was no calendar item in this message, do nothing else.
+
+
+       char *ser = icalcomponent_as_ical_string_r(ird.cal);
+       if (ser) {
+               size_t len = strlen(ser);
+               client_write(ser, len);
+               if ( (len>0) && (ser[len-1] != '\n') ) {
+                       syslog(LOG_DEBUG, "last char was %d", ser[len]);
+                       client_write(HKEY("\n"));
+               }
+               free(ser);
+       }
+
+
+       icalcomponent_free(ird.cal);            // Return the memory we got from the callback.
 }
 
 
+// Go through a calendar room and output calendar objects after applying caller specified filters.
+// It is intended as a data source for WebCit (both the UI and CalDAV)
 void calendar_report(void) {
-       char buf[SIZ];
+       void *filter_rules;     // Don't know yet what form this will take
 
        // Only allow this operation if we're in a room containing a calendar or tasks view
        if (    (CC->room.QRdefaultview != VIEW_CALENDAR)
@@ -34,21 +70,17 @@ void calendar_report(void) {
                return;         // This room does not contain a calendar.
        }
 
+       cprintf("%d Filtered calendar listing:\n", LISTING_FOLLOWS);
 
        // Now go through the room encapsulating all calendar items.
-       void *foo;
        CtdlForEachMessage(MSGS_ALL, 0, NULL,
                NULL,
                NULL,
                calendar_report_backend,
-               (void *) foo
+               (void *) filter_rules
        );
 
-       cprintf("%d Not finished\n", ERROR);
-       //cprintf("%d Send query then receive response\n", SEND_THEN_RECV);
-       //while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
-       //}
-       //cprintf("000\n");
+       cprintf("000\n");
 }
 
 
index e58c4ff6ffd79d0acab81505c3abca902a19a0be..005f5b5d7746fc5eb814f82500dc5256ed5086dd 100644 (file)
@@ -215,10 +215,12 @@ void smtp_hello(int which_command) {
                cprintf("250-SIZE %ld\r\n", CtdlGetConfigLong("c_maxmsglen"));
 
 #ifdef HAVE_OPENSSL
-               // Offer TLS, but only if TLS is not already active.
-               // Furthermore, only offer TLS when running on the SMTP-MSA port, not on the SMTP-MTA port,
-               // because if our server doesn't have a trusted certificate, some mailers will refuse to talk to it.
-               if ( (!CC->redirect_ssl) && (SMTP->is_msa) ) {
+               // Offer the STARTTLS option...
+               if (    (!CC->redirect_ssl)                                                     // not if we're already TLS
+                       && (    (SMTP->is_msa)                                                  // Always on port 587
+                               || (CtdlGetConfigInt("smtp_advertise_starttls") != 0)           // On port 25 only if enabled
+                       )
+               ) {
                        cprintf("250-STARTTLS\r\n");
                }
 #endif