| | @@ -403,13 +403,14 @@ |
| 403 | 403 | char *zErr; /* Error message */ |
| 404 | 404 | u32 mFlags; /* Flags */ |
| 405 | 405 | int bImmediateFail; /* On any error, call fossil_fatal() */ |
| 406 | 406 | }; |
| 407 | 407 | |
| 408 | | -/* Allowed values for EmailSender flags */ |
| 408 | +/* Allowed values for mFlags to email_sender_new(). |
| 409 | +*/ |
| 409 | 410 | #define EMAIL_IMMEDIATE_FAIL 0x0001 /* Call fossil_fatal() on any error */ |
| 410 | | -#define EMAIL_SMTP_TRACE 0x0002 /* Write SMTP transcript to console */ |
| 411 | +#define EMAIL_TRACE 0x0002 /* Log sending process on console */ |
| 411 | 412 | |
| 412 | 413 | #endif /* INTERFACE */ |
| 413 | 414 | |
| 414 | 415 | /* |
| 415 | 416 | ** Shutdown an emailer. Clear all information other than the error message. |
| | @@ -536,11 +537,11 @@ |
| 536 | 537 | }else if( fossil_strcmp(p->zDest, "relay")==0 ){ |
| 537 | 538 | const char *zRelay = 0; |
| 538 | 539 | emailerGetSetting(p, &zRelay, "email-send-relayhost"); |
| 539 | 540 | if( zRelay ){ |
| 540 | 541 | u32 smtpFlags = SMTP_DIRECT; |
| 541 | | - if( mFlags & EMAIL_SMTP_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT; |
| 542 | + if( mFlags & EMAIL_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT; |
| 542 | 543 | p->pSmtp = smtp_session_new(p->zFrom, zRelay, smtpFlags); |
| 543 | 544 | smtp_client_startup(p->pSmtp); |
| 544 | 545 | } |
| 545 | 546 | } |
| 546 | 547 | return p; |
| | @@ -694,10 +695,13 @@ |
| 694 | 695 | ** not free them. |
| 695 | 696 | */ |
| 696 | 697 | void email_send(EmailSender *p, Blob *pHdr, Blob *pBody){ |
| 697 | 698 | Blob all, *pOut; |
| 698 | 699 | u64 r1, r2; |
| 700 | + if( p->mFlags & EMAIL_TRACE ){ |
| 701 | + fossil_print("Sending email\n"); |
| 702 | + } |
| 699 | 703 | if( fossil_strcmp(p->zDest, "off")==0 ){ |
| 700 | 704 | return; |
| 701 | 705 | } |
| 702 | 706 | if( fossil_strcmp(p->zDest, "blob")==0 ){ |
| 703 | 707 | pOut = &p->out; |
| | @@ -943,11 +947,11 @@ |
| 943 | 947 | int i; |
| 944 | 948 | u32 mFlags = EMAIL_IMMEDIATE_FAIL; |
| 945 | 949 | const char *zSubject = find_option("subject", "S", 1); |
| 946 | 950 | const char *zSource = find_option("body", 0, 1); |
| 947 | 951 | EmailSender *pSender; |
| 948 | | - if( find_option("smtp-trace",0,0)!=0 ) mFlags |= EMAIL_SMTP_TRACE; |
| 952 | + if( find_option("smtp-trace",0,0)!=0 ) mFlags |= EMAIL_TRACE; |
| 949 | 953 | verify_all_options(); |
| 950 | 954 | blob_init(&prompt, 0, 0); |
| 951 | 955 | blob_init(&body, 0, 0); |
| 952 | 956 | blob_init(&hdr, 0, 0); |
| 953 | 957 | blob_appendf(&hdr,"To: "); |
| | @@ -1954,40 +1958,49 @@ |
| 1954 | 1958 | } |
| 1955 | 1959 | |
| 1956 | 1960 | /* |
| 1957 | 1961 | ** COMMAND: test-add-alerts |
| 1958 | 1962 | ** |
| 1959 | | -** Usage: %fossil test-add-alerts EVENTID ... |
| 1963 | +** Usage: %fossil test-add-alerts [--autoexec] EVENTID ... |
| 1960 | 1964 | ** |
| 1961 | 1965 | ** Add one or more events to the pending_alert queue. Use this |
| 1962 | 1966 | ** command during testing to force email notifications for specific |
| 1963 | 1967 | ** events. |
| 1964 | 1968 | ** |
| 1965 | 1969 | ** EVENTIDs are text. The first character is 'c', 'w', or 't' |
| 1966 | 1970 | ** for check-in, wiki, or ticket. The remaining text is a |
| 1967 | 1971 | ** integer that references the EVENT.OBJID value for the event. |
| 1968 | 1972 | ** Run /timeline?showid to see these OBJID values. |
| 1973 | +** |
| 1974 | +** If the --autoexec option is included, then email_auto_exec() is run |
| 1975 | +** after all alerts have been added. This will cause the alerts to |
| 1976 | +** be sent out with the SENDALERT_TRACE option. |
| 1969 | 1977 | */ |
| 1970 | 1978 | void test_add_alert_cmd(void){ |
| 1971 | 1979 | int i; |
| 1980 | + int doAuto = find_option("autoexec",0,0)!=0; |
| 1972 | 1981 | db_find_and_open_repository(0, 0); |
| 1973 | 1982 | verify_all_options(); |
| 1974 | | - db_begin_transaction(); |
| 1983 | + db_begin_write(); |
| 1975 | 1984 | email_schema(0); |
| 1976 | 1985 | for(i=2; i<g.argc; i++){ |
| 1977 | 1986 | db_multi_exec("REPLACE INTO pending_alert(eventId) VALUES(%Q)", g.argv[i]); |
| 1978 | 1987 | } |
| 1979 | 1988 | db_end_transaction(0); |
| 1989 | + if( doAuto ){ |
| 1990 | + email_auto_exec(SENDALERT_TRACE); |
| 1991 | + } |
| 1980 | 1992 | } |
| 1981 | 1993 | |
| 1982 | 1994 | #if INTERFACE |
| 1983 | 1995 | /* |
| 1984 | 1996 | ** Flags for email_send_alerts() |
| 1985 | 1997 | */ |
| 1986 | 1998 | #define SENDALERT_DIGEST 0x0001 /* Send a digest */ |
| 1987 | 1999 | #define SENDALERT_PRESERVE 0x0002 /* Do not mark the task as done */ |
| 1988 | 2000 | #define SENDALERT_STDOUT 0x0004 /* Print emails instead of sending */ |
| 2001 | +#define SENDALERT_TRACE 0x0008 /* Trace operation for debugging */ |
| 1989 | 2002 | |
| 1990 | 2003 | #endif /* INTERFACE */ |
| 1991 | 2004 | |
| 1992 | 2005 | /* |
| 1993 | 2006 | ** Send alert emails to all subscribers. |
| | @@ -2001,10 +2014,11 @@ |
| 2001 | 2014 | const char *zUrl; |
| 2002 | 2015 | const char *zRepoName; |
| 2003 | 2016 | const char *zFrom; |
| 2004 | 2017 | const char *zDest = (flags & SENDALERT_STDOUT) ? "stdout" : 0; |
| 2005 | 2018 | EmailSender *pSender = 0; |
| 2019 | + u32 senderFlags = 0; |
| 2006 | 2020 | |
| 2007 | 2021 | if( g.fSqlTrace ) fossil_trace("-- BEGIN email_send_alerts(%u)\n", flags); |
| 2008 | 2022 | db_begin_transaction(); |
| 2009 | 2023 | if( !email_enabled() ) goto send_alerts_done; |
| 2010 | 2024 | zUrl = db_get("email-url",0); |
| | @@ -2011,11 +2025,14 @@ |
| 2011 | 2025 | if( zUrl==0 ) goto send_alerts_done; |
| 2012 | 2026 | zRepoName = db_get("email-subname",0); |
| 2013 | 2027 | if( zRepoName==0 ) goto send_alerts_done; |
| 2014 | 2028 | zFrom = db_get("email-self",0); |
| 2015 | 2029 | if( zFrom==0 ) goto send_alerts_done; |
| 2016 | | - pSender = email_sender_new(zDest, 0); |
| 2030 | + if( flags & SENDALERT_TRACE ){ |
| 2031 | + senderFlags |= EMAIL_TRACE; |
| 2032 | + } |
| 2033 | + pSender = email_sender_new(zDest, senderFlags); |
| 2017 | 2034 | db_multi_exec( |
| 2018 | 2035 | "DROP TABLE IF EXISTS temp.wantalert;" |
| 2019 | 2036 | "CREATE TEMP TABLE wantalert(eventId TEXT);" |
| 2020 | 2037 | ); |
| 2021 | 2038 | if( flags & SENDALERT_DIGEST ){ |
| | @@ -2093,12 +2110,16 @@ |
| 2093 | 2110 | ** Check to see if any email notifications need to occur, and then |
| 2094 | 2111 | ** do them. |
| 2095 | 2112 | ** |
| 2096 | 2113 | ** This routine is called after certain webpages have been run and |
| 2097 | 2114 | ** have already responded. |
| 2115 | +** |
| 2116 | +** The mFlags option is zero or more of the SENDALERT_* flags. Normally |
| 2117 | +** this flag is zero, but the test-set-alert command sets it to |
| 2118 | +** SENDALERT_TRACE. |
| 2098 | 2119 | */ |
| 2099 | | -void email_auto_exec(void){ |
| 2120 | +void email_auto_exec(u32 mFlags){ |
| 2100 | 2121 | int iJulianDay; |
| 2101 | 2122 | if( g.db==0 ) return; |
| 2102 | 2123 | if( db_transaction_nesting_depth()!=0 ){ |
| 2103 | 2124 | fossil_warning("Called email_auto_exec() from within transaction " |
| 2104 | 2125 | "started at %z", db_transaction_start_point()); |
| | @@ -2105,18 +2126,18 @@ |
| 2105 | 2126 | return; |
| 2106 | 2127 | } |
| 2107 | 2128 | if( !email_tables_exist() ) return; |
| 2108 | 2129 | if( !db_get_boolean("email-autoexec",0) ) return; |
| 2109 | 2130 | db_begin_write(); |
| 2110 | | - email_send_alerts(0); |
| 2131 | + email_send_alerts(mFlags); |
| 2111 | 2132 | iJulianDay = db_int(0, "SELECT julianday('now')"); |
| 2112 | 2133 | if( iJulianDay>db_get_int("email-last-digest",0) ){ |
| 2113 | 2134 | if( db_transaction_nesting_depth()!=1 ){ |
| 2114 | 2135 | fossil_warning("Transaction nesting error prior to digest processing"); |
| 2115 | 2136 | }else{ |
| 2116 | 2137 | db_set_int("email-last-digest",iJulianDay,0); |
| 2117 | | - email_send_alerts(SENDALERT_DIGEST); |
| 2138 | + email_send_alerts(SENDALERT_DIGEST|mFlags); |
| 2118 | 2139 | } |
| 2119 | 2140 | } |
| 2120 | 2141 | db_commit_transaction(); |
| 2121 | 2142 | } |
| 2122 | 2143 | |
| 2123 | 2144 | |