Fossil SCM
Try to put the human name of the person who posted on the From: line of email notifications for new forum posts.
Commit
ad4193315f363aab15ea63f0fa782641e676ef25c04e45f847dd85729f43a374
Parent
b4602502114bef6…
2 files changed
+30
-13
+1
-1
+30
-13
| --- src/email.c | ||
| +++ src/email.c | ||
| @@ -724,11 +724,16 @@ | ||
| 724 | 724 | ** |
| 725 | 725 | ** The caller maintains ownership of the input Blobs. This routine will |
| 726 | 726 | ** read the Blobs and send them onward to the email system, but it will |
| 727 | 727 | ** not free them. |
| 728 | 728 | */ |
| 729 | -void email_send(EmailSender *p, Blob *pHdr, Blob *pBody){ | |
| 729 | +void email_send( | |
| 730 | + EmailSender *p, /* Emailer context */ | |
| 731 | + Blob *pHdr, /* Email header (incomplete) */ | |
| 732 | + Blob *pBody, /* Email body */ | |
| 733 | + const char *zFromName /* Optional human-readable name of sender */ | |
| 734 | +){ | |
| 730 | 735 | Blob all, *pOut; |
| 731 | 736 | u64 r1, r2; |
| 732 | 737 | if( p->mFlags & EMAIL_TRACE ){ |
| 733 | 738 | fossil_print("Sending email\n"); |
| 734 | 739 | } |
| @@ -743,11 +748,15 @@ | ||
| 743 | 748 | }else{ |
| 744 | 749 | blob_init(&all, 0, 0); |
| 745 | 750 | pOut = &all; |
| 746 | 751 | } |
| 747 | 752 | blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr)); |
| 748 | - blob_appendf(pOut, "From: <%s>\r\n", p->zFrom); | |
| 753 | + if( zFromName ){ | |
| 754 | + blob_appendf(pOut, "From: %s <%s>\r\n", zFromName, p->zFrom); | |
| 755 | + }else{ | |
| 756 | + blob_appendf(pOut, "From: <%s>\r\n", p->zFrom); | |
| 757 | + } | |
| 749 | 758 | blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0))); |
| 750 | 759 | if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){ |
| 751 | 760 | /* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is |
| 752 | 761 | ** the current unix-time in hex, $(random) is a 64-bit random number, |
| 753 | 762 | ** and $(from) is the sender. */ |
| @@ -1050,11 +1059,11 @@ | ||
| 1050 | 1059 | }else{ |
| 1051 | 1060 | prompt_for_user_comment(&body, &prompt); |
| 1052 | 1061 | } |
| 1053 | 1062 | blob_add_final_newline(&body); |
| 1054 | 1063 | pSender = email_sender_new(zDest, mFlags); |
| 1055 | - email_send(pSender, &hdr, &body); | |
| 1064 | + email_send(pSender, &hdr, &body, 0); | |
| 1056 | 1065 | email_sender_free(pSender); |
| 1057 | 1066 | blob_reset(&hdr); |
| 1058 | 1067 | blob_reset(&body); |
| 1059 | 1068 | blob_reset(&prompt); |
| 1060 | 1069 | }else |
| @@ -1269,11 +1278,11 @@ | ||
| 1269 | 1278 | blob_init(&hdr,0,0); |
| 1270 | 1279 | blob_init(&body,0,0); |
| 1271 | 1280 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1272 | 1281 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1273 | 1282 | email_append_confirmation_message(&body, zCode); |
| 1274 | - email_send(pSender, &hdr, &body); | |
| 1283 | + email_send(pSender, &hdr, &body, 0); | |
| 1275 | 1284 | style_header("Email Alert Verification"); |
| 1276 | 1285 | if( pSender->zErr ){ |
| 1277 | 1286 | @ <h1>Internal Error</h1> |
| 1278 | 1287 | @ <p>The following internal error was encountered while trying |
| 1279 | 1288 | @ to send the confirmation email: |
| @@ -1714,11 +1723,11 @@ | ||
| 1714 | 1723 | blob_init(&body,0,0); |
| 1715 | 1724 | blob_appendf(&hdr, "To: <%s>\r\n", zEAddr); |
| 1716 | 1725 | blob_appendf(&hdr, "Subject: Unsubscribe Instructions\r\n"); |
| 1717 | 1726 | blob_appendf(&body, zUnsubMsg/*works-like:"%s%s%s%s%s%s"*/, |
| 1718 | 1727 | g.zBaseURL, g.zBaseURL, zCode, g.zBaseURL, g.zBaseURL, zCode); |
| 1719 | - email_send(pSender, &hdr, &body); | |
| 1728 | + email_send(pSender, &hdr, &body, 0); | |
| 1720 | 1729 | style_header("Unsubscribe Instructions Sent"); |
| 1721 | 1730 | if( pSender->zErr ){ |
| 1722 | 1731 | @ <h1>Internal Error</h1> |
| 1723 | 1732 | @ <p>The following error was encountered while trying to send an |
| 1724 | 1733 | @ email to %h(zEAddr): |
| @@ -1863,10 +1872,11 @@ | ||
| 1863 | 1872 | struct EmailEvent { |
| 1864 | 1873 | int type; /* 'c', 'f', 'm', 't', 'w' */ |
| 1865 | 1874 | int needMod; /* Pending moderator approval */ |
| 1866 | 1875 | Blob hdr; /* Header content, for forum entries */ |
| 1867 | 1876 | Blob txt; /* Text description to appear in an alert */ |
| 1877 | + char *zFromName; /* Human name of the sender */ | |
| 1868 | 1878 | EmailEvent *pNext; /* Next in chronological order */ |
| 1869 | 1879 | }; |
| 1870 | 1880 | #endif |
| 1871 | 1881 | |
| 1872 | 1882 | /* |
| @@ -1875,10 +1885,11 @@ | ||
| 1875 | 1885 | void email_free_eventlist(EmailEvent *p){ |
| 1876 | 1886 | while( p ){ |
| 1877 | 1887 | EmailEvent *pNext = p->pNext; |
| 1878 | 1888 | blob_reset(&p->txt); |
| 1879 | 1889 | blob_reset(&p->hdr); |
| 1890 | + fossil_free(p->zFromName); | |
| 1880 | 1891 | fossil_free(p); |
| 1881 | 1892 | p = pNext; |
| 1882 | 1893 | } |
| 1883 | 1894 | } |
| 1884 | 1895 | |
| @@ -1929,10 +1940,11 @@ | ||
| 1929 | 1940 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 1930 | 1941 | pLast->pNext = p; |
| 1931 | 1942 | pLast = p; |
| 1932 | 1943 | p->type = db_column_text(&q, 3)[0]; |
| 1933 | 1944 | p->needMod = db_column_int(&q, 4); |
| 1945 | + p->zFromName = 0; | |
| 1934 | 1946 | p->pNext = 0; |
| 1935 | 1947 | switch( p->type ){ |
| 1936 | 1948 | case 'c': zType = "Check-In"; break; |
| 1937 | 1949 | case 'f': zType = "Forum post"; break; |
| 1938 | 1950 | case 't': zType = "Wiki Edit"; break; |
| @@ -1976,12 +1988,14 @@ | ||
| 1976 | 1988 | " forumpost.fpid," /* 0 */ |
| 1977 | 1989 | " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1 */ |
| 1978 | 1990 | " datetime(event.mtime)," /* 2 */ |
| 1979 | 1991 | " substr(comment,instr(comment,':')+2)," /* 3 */ |
| 1980 | 1992 | " (SELECT uuid FROM blob WHERE rid=forumpost.firt)," /* 4 */ |
| 1981 | - " wantalert.needMod" /* 5 */ | |
| 1993 | + " wantalert.needMod," /* 5 */ | |
| 1994 | + " coalesce(trim(substr(info,1,instr(info,'<')-1)),euser,user)" /* 6 */ | |
| 1982 | 1995 | " FROM temp.wantalert, event, forumpost" |
| 1996 | + " LEFT JOIN user ON (login=coalesce(euser,user))" | |
| 1983 | 1997 | " WHERE event.objid=substr(wantalert.eventId,2)+0" |
| 1984 | 1998 | " AND eventId GLOB 'f*'" |
| 1985 | 1999 | " AND forumpost.fpid=event.objid" |
| 1986 | 2000 | " ORDER BY event.mtime" |
| 1987 | 2001 | ); |
| @@ -1990,16 +2004,19 @@ | ||
| 1990 | 2004 | while( db_step(&q)==SQLITE_ROW ){ |
| 1991 | 2005 | Manifest *pPost = manifest_get(db_column_int(&q,0), CFTYPE_FORUM, 0); |
| 1992 | 2006 | const char *zIrt; |
| 1993 | 2007 | const char *zUuid; |
| 1994 | 2008 | const char *zTitle; |
| 2009 | + const char *z; | |
| 1995 | 2010 | if( pPost==0 ) continue; |
| 1996 | 2011 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 1997 | 2012 | pLast->pNext = p; |
| 1998 | 2013 | pLast = p; |
| 1999 | 2014 | p->type = 'f'; |
| 2000 | 2015 | p->needMod = db_column_int(&q, 5); |
| 2016 | + z = db_column_text(&q,6); | |
| 2017 | + p->zFromName = z && z[0] ? fossil_strdup(z) : 0; | |
| 2001 | 2018 | p->pNext = 0; |
| 2002 | 2019 | blob_init(&p->hdr, 0, 0); |
| 2003 | 2020 | zUuid = db_column_text(&q, 1); |
| 2004 | 2021 | zTitle = db_column_text(&q, 3); |
| 2005 | 2022 | if( p->needMod ){ |
| @@ -2303,12 +2320,12 @@ | ||
| 2303 | 2320 | db_prepare(&q, |
| 2304 | 2321 | "SELECT" |
| 2305 | 2322 | " hex(subscriberCode)," /* 0 */ |
| 2306 | 2323 | " semail," /* 1 */ |
| 2307 | 2324 | " ssub," /* 2 */ |
| 2308 | - " fullcap((SELECT cap FROM user WHERE login=suname))" /* 3 */ | |
| 2309 | - " FROM subscriber" | |
| 2325 | + " fullcap(user.cap)" /* 3 */ | |
| 2326 | + " FROM subscriber LEFT JOIN user ON (login=suname)" | |
| 2310 | 2327 | " WHERE sverified AND NOT sdonotcall" |
| 2311 | 2328 | " AND sdigest IS %s", |
| 2312 | 2329 | zDigest/*safe-for-%s*/ |
| 2313 | 2330 | ); |
| 2314 | 2331 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -2351,11 +2368,11 @@ | ||
| 2351 | 2368 | blob_appendf(&fhdr, "To: <%s>\r\n", zEmail); |
| 2352 | 2369 | blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr)); |
| 2353 | 2370 | blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt)); |
| 2354 | 2371 | blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n", |
| 2355 | 2372 | zUrl, zCode); |
| 2356 | - email_send(pSender,&fhdr,&fbody); | |
| 2373 | + email_send(pSender,&fhdr,&fbody,p->zFromName); | |
| 2357 | 2374 | blob_reset(&fhdr); |
| 2358 | 2375 | blob_reset(&fbody); |
| 2359 | 2376 | }else{ |
| 2360 | 2377 | /* Events other than forum posts are gathered together into |
| 2361 | 2378 | ** a single email message */ |
| @@ -2374,11 +2391,11 @@ | ||
| 2374 | 2391 | } |
| 2375 | 2392 | } |
| 2376 | 2393 | if( nHit==0 ) continue; |
| 2377 | 2394 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2378 | 2395 | zUrl, zCode); |
| 2379 | - email_send(pSender,&hdr,&body); | |
| 2396 | + email_send(pSender,&hdr,&body,0); | |
| 2380 | 2397 | blob_truncate(&hdr, 0); |
| 2381 | 2398 | blob_truncate(&body, 0); |
| 2382 | 2399 | } |
| 2383 | 2400 | blob_reset(&hdr); |
| 2384 | 2401 | blob_reset(&body); |
| @@ -2450,11 +2467,11 @@ | ||
| 2450 | 2467 | zAdminEmail, db_get("email-subname","Fossil Repo")); |
| 2451 | 2468 | blob_init(&body, 0, 0); |
| 2452 | 2469 | blob_appendf(&body, "Message from [%s]\n", PT("from")/*safe-for-%s*/); |
| 2453 | 2470 | blob_appendf(&body, "Subject: [%s]\n\n", PT("subject")/*safe-for-%s*/); |
| 2454 | 2471 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2455 | - email_send(pSender, &hdr, &body); | |
| 2472 | + email_send(pSender, &hdr, &body, 0); | |
| 2456 | 2473 | style_header("Message Sent"); |
| 2457 | 2474 | if( pSender->zErr ){ |
| 2458 | 2475 | @ <h1>Internal Error</h1> |
| 2459 | 2476 | @ <p>The following error was reported by the system: |
| 2460 | 2477 | @ <blockquote><pre> |
| @@ -2532,11 +2549,11 @@ | ||
| 2532 | 2549 | blob_init(&hdr, 0, 0); |
| 2533 | 2550 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2534 | 2551 | pSender = email_sender_new(bTest2 ? "blob" : 0, 0); |
| 2535 | 2552 | if( zTo[0] ){ |
| 2536 | 2553 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 2537 | - email_send(pSender, &hdr, &body); | |
| 2554 | + email_send(pSender, &hdr, &body, 0); | |
| 2538 | 2555 | } |
| 2539 | 2556 | if( bAll || bAA ){ |
| 2540 | 2557 | Stmt q; |
| 2541 | 2558 | int nUsed = blob_size(&body); |
| 2542 | 2559 | const char *zURL = db_get("email-url",0); |
| @@ -2551,11 +2568,11 @@ | ||
| 2551 | 2568 | if( zURL ){ |
| 2552 | 2569 | blob_truncate(&body, nUsed); |
| 2553 | 2570 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2554 | 2571 | zURL, zCode); |
| 2555 | 2572 | } |
| 2556 | - email_send(pSender, &hdr, &body); | |
| 2573 | + email_send(pSender, &hdr, &body, 0); | |
| 2557 | 2574 | } |
| 2558 | 2575 | db_finalize(&q); |
| 2559 | 2576 | } |
| 2560 | 2577 | if( bTest2 ){ |
| 2561 | 2578 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 2562 | 2579 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -724,11 +724,16 @@ | |
| 724 | ** |
| 725 | ** The caller maintains ownership of the input Blobs. This routine will |
| 726 | ** read the Blobs and send them onward to the email system, but it will |
| 727 | ** not free them. |
| 728 | */ |
| 729 | void email_send(EmailSender *p, Blob *pHdr, Blob *pBody){ |
| 730 | Blob all, *pOut; |
| 731 | u64 r1, r2; |
| 732 | if( p->mFlags & EMAIL_TRACE ){ |
| 733 | fossil_print("Sending email\n"); |
| 734 | } |
| @@ -743,11 +748,15 @@ | |
| 743 | }else{ |
| 744 | blob_init(&all, 0, 0); |
| 745 | pOut = &all; |
| 746 | } |
| 747 | blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr)); |
| 748 | blob_appendf(pOut, "From: <%s>\r\n", p->zFrom); |
| 749 | blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0))); |
| 750 | if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){ |
| 751 | /* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is |
| 752 | ** the current unix-time in hex, $(random) is a 64-bit random number, |
| 753 | ** and $(from) is the sender. */ |
| @@ -1050,11 +1059,11 @@ | |
| 1050 | }else{ |
| 1051 | prompt_for_user_comment(&body, &prompt); |
| 1052 | } |
| 1053 | blob_add_final_newline(&body); |
| 1054 | pSender = email_sender_new(zDest, mFlags); |
| 1055 | email_send(pSender, &hdr, &body); |
| 1056 | email_sender_free(pSender); |
| 1057 | blob_reset(&hdr); |
| 1058 | blob_reset(&body); |
| 1059 | blob_reset(&prompt); |
| 1060 | }else |
| @@ -1269,11 +1278,11 @@ | |
| 1269 | blob_init(&hdr,0,0); |
| 1270 | blob_init(&body,0,0); |
| 1271 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1272 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1273 | email_append_confirmation_message(&body, zCode); |
| 1274 | email_send(pSender, &hdr, &body); |
| 1275 | style_header("Email Alert Verification"); |
| 1276 | if( pSender->zErr ){ |
| 1277 | @ <h1>Internal Error</h1> |
| 1278 | @ <p>The following internal error was encountered while trying |
| 1279 | @ to send the confirmation email: |
| @@ -1714,11 +1723,11 @@ | |
| 1714 | blob_init(&body,0,0); |
| 1715 | blob_appendf(&hdr, "To: <%s>\r\n", zEAddr); |
| 1716 | blob_appendf(&hdr, "Subject: Unsubscribe Instructions\r\n"); |
| 1717 | blob_appendf(&body, zUnsubMsg/*works-like:"%s%s%s%s%s%s"*/, |
| 1718 | g.zBaseURL, g.zBaseURL, zCode, g.zBaseURL, g.zBaseURL, zCode); |
| 1719 | email_send(pSender, &hdr, &body); |
| 1720 | style_header("Unsubscribe Instructions Sent"); |
| 1721 | if( pSender->zErr ){ |
| 1722 | @ <h1>Internal Error</h1> |
| 1723 | @ <p>The following error was encountered while trying to send an |
| 1724 | @ email to %h(zEAddr): |
| @@ -1863,10 +1872,11 @@ | |
| 1863 | struct EmailEvent { |
| 1864 | int type; /* 'c', 'f', 'm', 't', 'w' */ |
| 1865 | int needMod; /* Pending moderator approval */ |
| 1866 | Blob hdr; /* Header content, for forum entries */ |
| 1867 | Blob txt; /* Text description to appear in an alert */ |
| 1868 | EmailEvent *pNext; /* Next in chronological order */ |
| 1869 | }; |
| 1870 | #endif |
| 1871 | |
| 1872 | /* |
| @@ -1875,10 +1885,11 @@ | |
| 1875 | void email_free_eventlist(EmailEvent *p){ |
| 1876 | while( p ){ |
| 1877 | EmailEvent *pNext = p->pNext; |
| 1878 | blob_reset(&p->txt); |
| 1879 | blob_reset(&p->hdr); |
| 1880 | fossil_free(p); |
| 1881 | p = pNext; |
| 1882 | } |
| 1883 | } |
| 1884 | |
| @@ -1929,10 +1940,11 @@ | |
| 1929 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 1930 | pLast->pNext = p; |
| 1931 | pLast = p; |
| 1932 | p->type = db_column_text(&q, 3)[0]; |
| 1933 | p->needMod = db_column_int(&q, 4); |
| 1934 | p->pNext = 0; |
| 1935 | switch( p->type ){ |
| 1936 | case 'c': zType = "Check-In"; break; |
| 1937 | case 'f': zType = "Forum post"; break; |
| 1938 | case 't': zType = "Wiki Edit"; break; |
| @@ -1976,12 +1988,14 @@ | |
| 1976 | " forumpost.fpid," /* 0 */ |
| 1977 | " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1 */ |
| 1978 | " datetime(event.mtime)," /* 2 */ |
| 1979 | " substr(comment,instr(comment,':')+2)," /* 3 */ |
| 1980 | " (SELECT uuid FROM blob WHERE rid=forumpost.firt)," /* 4 */ |
| 1981 | " wantalert.needMod" /* 5 */ |
| 1982 | " FROM temp.wantalert, event, forumpost" |
| 1983 | " WHERE event.objid=substr(wantalert.eventId,2)+0" |
| 1984 | " AND eventId GLOB 'f*'" |
| 1985 | " AND forumpost.fpid=event.objid" |
| 1986 | " ORDER BY event.mtime" |
| 1987 | ); |
| @@ -1990,16 +2004,19 @@ | |
| 1990 | while( db_step(&q)==SQLITE_ROW ){ |
| 1991 | Manifest *pPost = manifest_get(db_column_int(&q,0), CFTYPE_FORUM, 0); |
| 1992 | const char *zIrt; |
| 1993 | const char *zUuid; |
| 1994 | const char *zTitle; |
| 1995 | if( pPost==0 ) continue; |
| 1996 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 1997 | pLast->pNext = p; |
| 1998 | pLast = p; |
| 1999 | p->type = 'f'; |
| 2000 | p->needMod = db_column_int(&q, 5); |
| 2001 | p->pNext = 0; |
| 2002 | blob_init(&p->hdr, 0, 0); |
| 2003 | zUuid = db_column_text(&q, 1); |
| 2004 | zTitle = db_column_text(&q, 3); |
| 2005 | if( p->needMod ){ |
| @@ -2303,12 +2320,12 @@ | |
| 2303 | db_prepare(&q, |
| 2304 | "SELECT" |
| 2305 | " hex(subscriberCode)," /* 0 */ |
| 2306 | " semail," /* 1 */ |
| 2307 | " ssub," /* 2 */ |
| 2308 | " fullcap((SELECT cap FROM user WHERE login=suname))" /* 3 */ |
| 2309 | " FROM subscriber" |
| 2310 | " WHERE sverified AND NOT sdonotcall" |
| 2311 | " AND sdigest IS %s", |
| 2312 | zDigest/*safe-for-%s*/ |
| 2313 | ); |
| 2314 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -2351,11 +2368,11 @@ | |
| 2351 | blob_appendf(&fhdr, "To: <%s>\r\n", zEmail); |
| 2352 | blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr)); |
| 2353 | blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt)); |
| 2354 | blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n", |
| 2355 | zUrl, zCode); |
| 2356 | email_send(pSender,&fhdr,&fbody); |
| 2357 | blob_reset(&fhdr); |
| 2358 | blob_reset(&fbody); |
| 2359 | }else{ |
| 2360 | /* Events other than forum posts are gathered together into |
| 2361 | ** a single email message */ |
| @@ -2374,11 +2391,11 @@ | |
| 2374 | } |
| 2375 | } |
| 2376 | if( nHit==0 ) continue; |
| 2377 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2378 | zUrl, zCode); |
| 2379 | email_send(pSender,&hdr,&body); |
| 2380 | blob_truncate(&hdr, 0); |
| 2381 | blob_truncate(&body, 0); |
| 2382 | } |
| 2383 | blob_reset(&hdr); |
| 2384 | blob_reset(&body); |
| @@ -2450,11 +2467,11 @@ | |
| 2450 | zAdminEmail, db_get("email-subname","Fossil Repo")); |
| 2451 | blob_init(&body, 0, 0); |
| 2452 | blob_appendf(&body, "Message from [%s]\n", PT("from")/*safe-for-%s*/); |
| 2453 | blob_appendf(&body, "Subject: [%s]\n\n", PT("subject")/*safe-for-%s*/); |
| 2454 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2455 | email_send(pSender, &hdr, &body); |
| 2456 | style_header("Message Sent"); |
| 2457 | if( pSender->zErr ){ |
| 2458 | @ <h1>Internal Error</h1> |
| 2459 | @ <p>The following error was reported by the system: |
| 2460 | @ <blockquote><pre> |
| @@ -2532,11 +2549,11 @@ | |
| 2532 | blob_init(&hdr, 0, 0); |
| 2533 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2534 | pSender = email_sender_new(bTest2 ? "blob" : 0, 0); |
| 2535 | if( zTo[0] ){ |
| 2536 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 2537 | email_send(pSender, &hdr, &body); |
| 2538 | } |
| 2539 | if( bAll || bAA ){ |
| 2540 | Stmt q; |
| 2541 | int nUsed = blob_size(&body); |
| 2542 | const char *zURL = db_get("email-url",0); |
| @@ -2551,11 +2568,11 @@ | |
| 2551 | if( zURL ){ |
| 2552 | blob_truncate(&body, nUsed); |
| 2553 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2554 | zURL, zCode); |
| 2555 | } |
| 2556 | email_send(pSender, &hdr, &body); |
| 2557 | } |
| 2558 | db_finalize(&q); |
| 2559 | } |
| 2560 | if( bTest2 ){ |
| 2561 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 2562 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -724,11 +724,16 @@ | |
| 724 | ** |
| 725 | ** The caller maintains ownership of the input Blobs. This routine will |
| 726 | ** read the Blobs and send them onward to the email system, but it will |
| 727 | ** not free them. |
| 728 | */ |
| 729 | void email_send( |
| 730 | EmailSender *p, /* Emailer context */ |
| 731 | Blob *pHdr, /* Email header (incomplete) */ |
| 732 | Blob *pBody, /* Email body */ |
| 733 | const char *zFromName /* Optional human-readable name of sender */ |
| 734 | ){ |
| 735 | Blob all, *pOut; |
| 736 | u64 r1, r2; |
| 737 | if( p->mFlags & EMAIL_TRACE ){ |
| 738 | fossil_print("Sending email\n"); |
| 739 | } |
| @@ -743,11 +748,15 @@ | |
| 748 | }else{ |
| 749 | blob_init(&all, 0, 0); |
| 750 | pOut = &all; |
| 751 | } |
| 752 | blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr)); |
| 753 | if( zFromName ){ |
| 754 | blob_appendf(pOut, "From: %s <%s>\r\n", zFromName, p->zFrom); |
| 755 | }else{ |
| 756 | blob_appendf(pOut, "From: <%s>\r\n", p->zFrom); |
| 757 | } |
| 758 | blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0))); |
| 759 | if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){ |
| 760 | /* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is |
| 761 | ** the current unix-time in hex, $(random) is a 64-bit random number, |
| 762 | ** and $(from) is the sender. */ |
| @@ -1050,11 +1059,11 @@ | |
| 1059 | }else{ |
| 1060 | prompt_for_user_comment(&body, &prompt); |
| 1061 | } |
| 1062 | blob_add_final_newline(&body); |
| 1063 | pSender = email_sender_new(zDest, mFlags); |
| 1064 | email_send(pSender, &hdr, &body, 0); |
| 1065 | email_sender_free(pSender); |
| 1066 | blob_reset(&hdr); |
| 1067 | blob_reset(&body); |
| 1068 | blob_reset(&prompt); |
| 1069 | }else |
| @@ -1269,11 +1278,11 @@ | |
| 1278 | blob_init(&hdr,0,0); |
| 1279 | blob_init(&body,0,0); |
| 1280 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1281 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1282 | email_append_confirmation_message(&body, zCode); |
| 1283 | email_send(pSender, &hdr, &body, 0); |
| 1284 | style_header("Email Alert Verification"); |
| 1285 | if( pSender->zErr ){ |
| 1286 | @ <h1>Internal Error</h1> |
| 1287 | @ <p>The following internal error was encountered while trying |
| 1288 | @ to send the confirmation email: |
| @@ -1714,11 +1723,11 @@ | |
| 1723 | blob_init(&body,0,0); |
| 1724 | blob_appendf(&hdr, "To: <%s>\r\n", zEAddr); |
| 1725 | blob_appendf(&hdr, "Subject: Unsubscribe Instructions\r\n"); |
| 1726 | blob_appendf(&body, zUnsubMsg/*works-like:"%s%s%s%s%s%s"*/, |
| 1727 | g.zBaseURL, g.zBaseURL, zCode, g.zBaseURL, g.zBaseURL, zCode); |
| 1728 | email_send(pSender, &hdr, &body, 0); |
| 1729 | style_header("Unsubscribe Instructions Sent"); |
| 1730 | if( pSender->zErr ){ |
| 1731 | @ <h1>Internal Error</h1> |
| 1732 | @ <p>The following error was encountered while trying to send an |
| 1733 | @ email to %h(zEAddr): |
| @@ -1863,10 +1872,11 @@ | |
| 1872 | struct EmailEvent { |
| 1873 | int type; /* 'c', 'f', 'm', 't', 'w' */ |
| 1874 | int needMod; /* Pending moderator approval */ |
| 1875 | Blob hdr; /* Header content, for forum entries */ |
| 1876 | Blob txt; /* Text description to appear in an alert */ |
| 1877 | char *zFromName; /* Human name of the sender */ |
| 1878 | EmailEvent *pNext; /* Next in chronological order */ |
| 1879 | }; |
| 1880 | #endif |
| 1881 | |
| 1882 | /* |
| @@ -1875,10 +1885,11 @@ | |
| 1885 | void email_free_eventlist(EmailEvent *p){ |
| 1886 | while( p ){ |
| 1887 | EmailEvent *pNext = p->pNext; |
| 1888 | blob_reset(&p->txt); |
| 1889 | blob_reset(&p->hdr); |
| 1890 | fossil_free(p->zFromName); |
| 1891 | fossil_free(p); |
| 1892 | p = pNext; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| @@ -1929,10 +1940,11 @@ | |
| 1940 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 1941 | pLast->pNext = p; |
| 1942 | pLast = p; |
| 1943 | p->type = db_column_text(&q, 3)[0]; |
| 1944 | p->needMod = db_column_int(&q, 4); |
| 1945 | p->zFromName = 0; |
| 1946 | p->pNext = 0; |
| 1947 | switch( p->type ){ |
| 1948 | case 'c': zType = "Check-In"; break; |
| 1949 | case 'f': zType = "Forum post"; break; |
| 1950 | case 't': zType = "Wiki Edit"; break; |
| @@ -1976,12 +1988,14 @@ | |
| 1988 | " forumpost.fpid," /* 0 */ |
| 1989 | " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1 */ |
| 1990 | " datetime(event.mtime)," /* 2 */ |
| 1991 | " substr(comment,instr(comment,':')+2)," /* 3 */ |
| 1992 | " (SELECT uuid FROM blob WHERE rid=forumpost.firt)," /* 4 */ |
| 1993 | " wantalert.needMod," /* 5 */ |
| 1994 | " coalesce(trim(substr(info,1,instr(info,'<')-1)),euser,user)" /* 6 */ |
| 1995 | " FROM temp.wantalert, event, forumpost" |
| 1996 | " LEFT JOIN user ON (login=coalesce(euser,user))" |
| 1997 | " WHERE event.objid=substr(wantalert.eventId,2)+0" |
| 1998 | " AND eventId GLOB 'f*'" |
| 1999 | " AND forumpost.fpid=event.objid" |
| 2000 | " ORDER BY event.mtime" |
| 2001 | ); |
| @@ -1990,16 +2004,19 @@ | |
| 2004 | while( db_step(&q)==SQLITE_ROW ){ |
| 2005 | Manifest *pPost = manifest_get(db_column_int(&q,0), CFTYPE_FORUM, 0); |
| 2006 | const char *zIrt; |
| 2007 | const char *zUuid; |
| 2008 | const char *zTitle; |
| 2009 | const char *z; |
| 2010 | if( pPost==0 ) continue; |
| 2011 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 2012 | pLast->pNext = p; |
| 2013 | pLast = p; |
| 2014 | p->type = 'f'; |
| 2015 | p->needMod = db_column_int(&q, 5); |
| 2016 | z = db_column_text(&q,6); |
| 2017 | p->zFromName = z && z[0] ? fossil_strdup(z) : 0; |
| 2018 | p->pNext = 0; |
| 2019 | blob_init(&p->hdr, 0, 0); |
| 2020 | zUuid = db_column_text(&q, 1); |
| 2021 | zTitle = db_column_text(&q, 3); |
| 2022 | if( p->needMod ){ |
| @@ -2303,12 +2320,12 @@ | |
| 2320 | db_prepare(&q, |
| 2321 | "SELECT" |
| 2322 | " hex(subscriberCode)," /* 0 */ |
| 2323 | " semail," /* 1 */ |
| 2324 | " ssub," /* 2 */ |
| 2325 | " fullcap(user.cap)" /* 3 */ |
| 2326 | " FROM subscriber LEFT JOIN user ON (login=suname)" |
| 2327 | " WHERE sverified AND NOT sdonotcall" |
| 2328 | " AND sdigest IS %s", |
| 2329 | zDigest/*safe-for-%s*/ |
| 2330 | ); |
| 2331 | while( db_step(&q)==SQLITE_ROW ){ |
| @@ -2351,11 +2368,11 @@ | |
| 2368 | blob_appendf(&fhdr, "To: <%s>\r\n", zEmail); |
| 2369 | blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr)); |
| 2370 | blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt)); |
| 2371 | blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n", |
| 2372 | zUrl, zCode); |
| 2373 | email_send(pSender,&fhdr,&fbody,p->zFromName); |
| 2374 | blob_reset(&fhdr); |
| 2375 | blob_reset(&fbody); |
| 2376 | }else{ |
| 2377 | /* Events other than forum posts are gathered together into |
| 2378 | ** a single email message */ |
| @@ -2374,11 +2391,11 @@ | |
| 2391 | } |
| 2392 | } |
| 2393 | if( nHit==0 ) continue; |
| 2394 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2395 | zUrl, zCode); |
| 2396 | email_send(pSender,&hdr,&body,0); |
| 2397 | blob_truncate(&hdr, 0); |
| 2398 | blob_truncate(&body, 0); |
| 2399 | } |
| 2400 | blob_reset(&hdr); |
| 2401 | blob_reset(&body); |
| @@ -2450,11 +2467,11 @@ | |
| 2467 | zAdminEmail, db_get("email-subname","Fossil Repo")); |
| 2468 | blob_init(&body, 0, 0); |
| 2469 | blob_appendf(&body, "Message from [%s]\n", PT("from")/*safe-for-%s*/); |
| 2470 | blob_appendf(&body, "Subject: [%s]\n\n", PT("subject")/*safe-for-%s*/); |
| 2471 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2472 | email_send(pSender, &hdr, &body, 0); |
| 2473 | style_header("Message Sent"); |
| 2474 | if( pSender->zErr ){ |
| 2475 | @ <h1>Internal Error</h1> |
| 2476 | @ <p>The following error was reported by the system: |
| 2477 | @ <blockquote><pre> |
| @@ -2532,11 +2549,11 @@ | |
| 2549 | blob_init(&hdr, 0, 0); |
| 2550 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 2551 | pSender = email_sender_new(bTest2 ? "blob" : 0, 0); |
| 2552 | if( zTo[0] ){ |
| 2553 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 2554 | email_send(pSender, &hdr, &body, 0); |
| 2555 | } |
| 2556 | if( bAll || bAA ){ |
| 2557 | Stmt q; |
| 2558 | int nUsed = blob_size(&body); |
| 2559 | const char *zURL = db_get("email-url",0); |
| @@ -2551,11 +2568,11 @@ | |
| 2568 | if( zURL ){ |
| 2569 | blob_truncate(&body, nUsed); |
| 2570 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2571 | zURL, zCode); |
| 2572 | } |
| 2573 | email_send(pSender, &hdr, &body, 0); |
| 2574 | } |
| 2575 | db_finalize(&q); |
| 2576 | } |
| 2577 | if( bTest2 ){ |
| 2578 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 2579 |
+1
-1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -1622,11 +1622,11 @@ | ||
| 1622 | 1622 | blob_init(&hdr,0,0); |
| 1623 | 1623 | blob_init(&body,0,0); |
| 1624 | 1624 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1625 | 1625 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1626 | 1626 | email_append_confirmation_message(&body, zCode); |
| 1627 | - email_send(pSender, &hdr, &body); | |
| 1627 | + email_send(pSender, &hdr, &body, 0); | |
| 1628 | 1628 | style_header("Email Verification"); |
| 1629 | 1629 | if( pSender->zErr ){ |
| 1630 | 1630 | @ <h1>Internal Error</h1> |
| 1631 | 1631 | @ <p>The following internal error was encountered while trying |
| 1632 | 1632 | @ to send the confirmation email: |
| 1633 | 1633 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1622,11 +1622,11 @@ | |
| 1622 | blob_init(&hdr,0,0); |
| 1623 | blob_init(&body,0,0); |
| 1624 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1625 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1626 | email_append_confirmation_message(&body, zCode); |
| 1627 | email_send(pSender, &hdr, &body); |
| 1628 | style_header("Email Verification"); |
| 1629 | if( pSender->zErr ){ |
| 1630 | @ <h1>Internal Error</h1> |
| 1631 | @ <p>The following internal error was encountered while trying |
| 1632 | @ to send the confirmation email: |
| 1633 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1622,11 +1622,11 @@ | |
| 1622 | blob_init(&hdr,0,0); |
| 1623 | blob_init(&body,0,0); |
| 1624 | blob_appendf(&hdr, "To: <%s>\n", zEAddr); |
| 1625 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 1626 | email_append_confirmation_message(&body, zCode); |
| 1627 | email_send(pSender, &hdr, &body, 0); |
| 1628 | style_header("Email Verification"); |
| 1629 | if( pSender->zErr ){ |
| 1630 | @ <h1>Internal Error</h1> |
| 1631 | @ <p>The following internal error was encountered while trying |
| 1632 | @ to send the confirmation email: |
| 1633 |