Fossil SCM

Improvements to formatting in generated emails to make them appear less like spam. Suggestions from "gahr" on the forum.

drh 2018-08-09 15:39 trunk
Commit 27404ad05f378c180e87a146d7054032e709dd1e4396252b4d54587dcff177fe
1 file changed +23 -5
+23 -5
--- src/email.c
+++ src/email.c
@@ -619,10 +619,24 @@
619619
if( nDot==0 ) return 0; /* No "." in the domain */
620620
621621
/* If we reach this point, the email address is valid */
622622
return mprintf("%.*s", i, z);
623623
}
624
+
625
+/*
626
+** Return the hostname portion of an email address - the part following
627
+** the @
628
+*/
629
+char *email_hostname(const char *zAddr){
630
+ char *z = strchr(zAddr, '@');
631
+ if( z ){
632
+ z++;
633
+ }else{
634
+ z = (char*)zAddr;
635
+ }
636
+ return z;
637
+}
624638
625639
/*
626640
** Extract all To: header values from the email header supplied.
627641
** Store them in the array list.
628642
*/
@@ -668,10 +682,11 @@
668682
** From:
669683
** Date:
670684
** Message-Id:
671685
** Content-Type:
672686
** Content-Transfer-Encoding:
687
+** MIME-Version:
673688
**
674689
** The caller maintains ownership of the input Blobs. This routine will
675690
** read the Blobs and send them onward to the email system, but it will
676691
** not free them.
677692
*/
@@ -700,14 +715,16 @@
700715
/* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is
701716
** the current unix-time in hex, $(random) is a 64-bit random number,
702717
** and $(from) is the sender. */
703718
sqlite3_randomness(sizeof(r1), &r1);
704719
r2 = time(0);
705
- blob_appendf(pOut, "Message-Id: <%llxx%016llx.%s>\r\n", r2, r1, p->zFrom);
720
+ blob_appendf(pOut, "Message-Id: <%llxx%016llx@%s>\r\n",
721
+ r2, r1, email_hostname(p->zFrom));
706722
}
707723
blob_add_final_newline(pBody);
708
- blob_appendf(pOut,"Content-Type: text/plain\r\n");
724
+ blob_appendf(pOut, "MIME-Version: 1.0\r\n");
725
+ blob_appendf(pOut, "Content-Type: text/plain; charset=\"UTF-8\"\r\n");
709726
#if 0
710727
blob_appendf(pOut, "Content-Transfer-Encoding: base64\r\n\r\n");
711728
append_base64(pOut, pBody);
712729
#else
713730
blob_appendf(pOut, "Content-Transfer-Encoding: quoted-printable\r\n\r\n");
@@ -1951,14 +1968,16 @@
19511968
if( p->needMod ){
19521969
blob_appendf(&p->hdr, "Subject: %s Pending Moderation: %s\r\n",
19531970
zSub, zTitle);
19541971
}else{
19551972
blob_appendf(&p->hdr, "Subject: %s %s\r\n", zSub, zTitle);
1956
- blob_appendf(&p->hdr, "Message-Id: <%s.%s>\r\n", zUuid, zFrom);
1973
+ blob_appendf(&p->hdr, "Message-Id: <%.32s@%s>\r\n",
1974
+ zUuid, email_hostname(zFrom));
19571975
zIrt = db_column_text(&q, 4);
19581976
if( zIrt && zIrt[0] ){
1959
- blob_appendf(&p->hdr, "In-Reply-To: <%s.%s>\r\n", zIrt, zFrom);
1977
+ blob_appendf(&p->hdr, "In-Reply-To: <%.32s@%s>\r\n",
1978
+ zIrt, email_hostname(zFrom));
19601979
}
19611980
}
19621981
blob_init(&p->txt, 0, 0);
19631982
if( p->needMod ){
19641983
blob_appendf(&p->txt,
@@ -2335,11 +2354,10 @@
23352354
db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
23362355
23372356
send_alerts_done:
23382357
email_sender_free(pSender);
23392358
if( g.fSqlTrace ) fossil_trace("-- END email_send_alerts(%u)\n", flags);
2340
- db_end_transaction(0);
23412359
}
23422360
23432361
/*
23442362
** Do backoffice processing for email notifications. In other words,
23452363
** check to see if any email notifications need to occur, and then
23462364
--- src/email.c
+++ src/email.c
@@ -619,10 +619,24 @@
619 if( nDot==0 ) return 0; /* No "." in the domain */
620
621 /* If we reach this point, the email address is valid */
622 return mprintf("%.*s", i, z);
623 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624
625 /*
626 ** Extract all To: header values from the email header supplied.
627 ** Store them in the array list.
628 */
@@ -668,10 +682,11 @@
668 ** From:
669 ** Date:
670 ** Message-Id:
671 ** Content-Type:
672 ** Content-Transfer-Encoding:
 
673 **
674 ** The caller maintains ownership of the input Blobs. This routine will
675 ** read the Blobs and send them onward to the email system, but it will
676 ** not free them.
677 */
@@ -700,14 +715,16 @@
700 /* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is
701 ** the current unix-time in hex, $(random) is a 64-bit random number,
702 ** and $(from) is the sender. */
703 sqlite3_randomness(sizeof(r1), &r1);
704 r2 = time(0);
705 blob_appendf(pOut, "Message-Id: <%llxx%016llx.%s>\r\n", r2, r1, p->zFrom);
 
706 }
707 blob_add_final_newline(pBody);
708 blob_appendf(pOut,"Content-Type: text/plain\r\n");
 
709 #if 0
710 blob_appendf(pOut, "Content-Transfer-Encoding: base64\r\n\r\n");
711 append_base64(pOut, pBody);
712 #else
713 blob_appendf(pOut, "Content-Transfer-Encoding: quoted-printable\r\n\r\n");
@@ -1951,14 +1968,16 @@
1951 if( p->needMod ){
1952 blob_appendf(&p->hdr, "Subject: %s Pending Moderation: %s\r\n",
1953 zSub, zTitle);
1954 }else{
1955 blob_appendf(&p->hdr, "Subject: %s %s\r\n", zSub, zTitle);
1956 blob_appendf(&p->hdr, "Message-Id: <%s.%s>\r\n", zUuid, zFrom);
 
1957 zIrt = db_column_text(&q, 4);
1958 if( zIrt && zIrt[0] ){
1959 blob_appendf(&p->hdr, "In-Reply-To: <%s.%s>\r\n", zIrt, zFrom);
 
1960 }
1961 }
1962 blob_init(&p->txt, 0, 0);
1963 if( p->needMod ){
1964 blob_appendf(&p->txt,
@@ -2335,11 +2354,10 @@
2335 db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
2336
2337 send_alerts_done:
2338 email_sender_free(pSender);
2339 if( g.fSqlTrace ) fossil_trace("-- END email_send_alerts(%u)\n", flags);
2340 db_end_transaction(0);
2341 }
2342
2343 /*
2344 ** Do backoffice processing for email notifications. In other words,
2345 ** check to see if any email notifications need to occur, and then
2346
--- src/email.c
+++ src/email.c
@@ -619,10 +619,24 @@
619 if( nDot==0 ) return 0; /* No "." in the domain */
620
621 /* If we reach this point, the email address is valid */
622 return mprintf("%.*s", i, z);
623 }
624
625 /*
626 ** Return the hostname portion of an email address - the part following
627 ** the @
628 */
629 char *email_hostname(const char *zAddr){
630 char *z = strchr(zAddr, '@');
631 if( z ){
632 z++;
633 }else{
634 z = (char*)zAddr;
635 }
636 return z;
637 }
638
639 /*
640 ** Extract all To: header values from the email header supplied.
641 ** Store them in the array list.
642 */
@@ -668,10 +682,11 @@
682 ** From:
683 ** Date:
684 ** Message-Id:
685 ** Content-Type:
686 ** Content-Transfer-Encoding:
687 ** MIME-Version:
688 **
689 ** The caller maintains ownership of the input Blobs. This routine will
690 ** read the Blobs and send them onward to the email system, but it will
691 ** not free them.
692 */
@@ -700,14 +715,16 @@
715 /* Message-id format: "<$(date)x$(random).$(from)>" where $(date) is
716 ** the current unix-time in hex, $(random) is a 64-bit random number,
717 ** and $(from) is the sender. */
718 sqlite3_randomness(sizeof(r1), &r1);
719 r2 = time(0);
720 blob_appendf(pOut, "Message-Id: <%llxx%016llx@%s>\r\n",
721 r2, r1, email_hostname(p->zFrom));
722 }
723 blob_add_final_newline(pBody);
724 blob_appendf(pOut, "MIME-Version: 1.0\r\n");
725 blob_appendf(pOut, "Content-Type: text/plain; charset=\"UTF-8\"\r\n");
726 #if 0
727 blob_appendf(pOut, "Content-Transfer-Encoding: base64\r\n\r\n");
728 append_base64(pOut, pBody);
729 #else
730 blob_appendf(pOut, "Content-Transfer-Encoding: quoted-printable\r\n\r\n");
@@ -1951,14 +1968,16 @@
1968 if( p->needMod ){
1969 blob_appendf(&p->hdr, "Subject: %s Pending Moderation: %s\r\n",
1970 zSub, zTitle);
1971 }else{
1972 blob_appendf(&p->hdr, "Subject: %s %s\r\n", zSub, zTitle);
1973 blob_appendf(&p->hdr, "Message-Id: <%.32s@%s>\r\n",
1974 zUuid, email_hostname(zFrom));
1975 zIrt = db_column_text(&q, 4);
1976 if( zIrt && zIrt[0] ){
1977 blob_appendf(&p->hdr, "In-Reply-To: <%.32s@%s>\r\n",
1978 zIrt, email_hostname(zFrom));
1979 }
1980 }
1981 blob_init(&p->txt, 0, 0);
1982 if( p->needMod ){
1983 blob_appendf(&p->txt,
@@ -2335,11 +2354,10 @@
2354 db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
2355
2356 send_alerts_done:
2357 email_sender_free(pSender);
2358 if( g.fSqlTrace ) fossil_trace("-- END email_send_alerts(%u)\n", flags);
 
2359 }
2360
2361 /*
2362 ** Do backoffice processing for email notifications. In other words,
2363 ** check to see if any email notifications need to occur, and then
2364

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button