Fossil SCM

Add a setup menu option for Email-Server. Try to get the build of this branch working (without DNS support) for non-linux systems.

drh 2018-07-11 19:41 smtp
Commit aa80d6941e8e9a53e5d593e36256b92d99a255e3bbd2986ecae37f42252a6642
+4 -4
--- src/email.c
+++ src/email.c
@@ -181,16 +181,16 @@
181181
}
182182
}
183183
184184
185185
/*
186
-** WEBPAGE: setup_email
186
+** WEBPAGE: setup_notification
187187
**
188188
** Administrative page for configuring and controlling email notification.
189
-** Normally accessible via the /Admin/Email menu.
189
+** Normally accessible via the /Admin/Notification menu.
190190
*/
191
-void setup_email(void){
191
+void setup_notification(void){
192192
static const char *const azSendMethods[] = {
193193
"off", "Disabled",
194194
"pipe", "Pipe to a command",
195195
"db", "Store in a database",
196196
"dir", "Store in a directory",
@@ -203,11 +203,11 @@
203203
}
204204
db_begin_transaction();
205205
206206
email_submenu_common();
207207
style_header("Email Notification Setup");
208
- @ <form action="%R/setup_email" method="post"><div>
208
+ @ <form action="%R/setup_notification" method="post"><div>
209209
@ <input type="submit" name="submit" value="Apply Changes" /><hr>
210210
login_insert_csrf_secret();
211211
212212
entry_attribute("Canonical Server URL", 40, "email-url",
213213
"eurl", "", 0);
214214
--- src/email.c
+++ src/email.c
@@ -181,16 +181,16 @@
181 }
182 }
183
184
185 /*
186 ** WEBPAGE: setup_email
187 **
188 ** Administrative page for configuring and controlling email notification.
189 ** Normally accessible via the /Admin/Email menu.
190 */
191 void setup_email(void){
192 static const char *const azSendMethods[] = {
193 "off", "Disabled",
194 "pipe", "Pipe to a command",
195 "db", "Store in a database",
196 "dir", "Store in a directory",
@@ -203,11 +203,11 @@
203 }
204 db_begin_transaction();
205
206 email_submenu_common();
207 style_header("Email Notification Setup");
208 @ <form action="%R/setup_email" method="post"><div>
209 @ <input type="submit" name="submit" value="Apply Changes" /><hr>
210 login_insert_csrf_secret();
211
212 entry_attribute("Canonical Server URL", 40, "email-url",
213 "eurl", "", 0);
214
--- src/email.c
+++ src/email.c
@@ -181,16 +181,16 @@
181 }
182 }
183
184
185 /*
186 ** WEBPAGE: setup_notification
187 **
188 ** Administrative page for configuring and controlling email notification.
189 ** Normally accessible via the /Admin/Notification menu.
190 */
191 void setup_notification(void){
192 static const char *const azSendMethods[] = {
193 "off", "Disabled",
194 "pipe", "Pipe to a command",
195 "db", "Store in a database",
196 "dir", "Store in a directory",
@@ -203,11 +203,11 @@
203 }
204 db_begin_transaction();
205
206 email_submenu_common();
207 style_header("Email Notification Setup");
208 @ <form action="%R/setup_notification" method="post"><div>
209 @ <input type="submit" name="submit" value="Apply Changes" /><hr>
210 login_insert_csrf_secret();
211
212 entry_attribute("Canonical Server URL", 40, "email-url",
213 "eurl", "", 0);
214
+4 -1
--- src/setup.c
+++ src/setup.c
@@ -114,11 +114,14 @@
114114
"Configure the trouble-ticketing system for this repository");
115115
setup_menu_entry("Search","srchsetup",
116116
"Configure the built-in search engine");
117117
setup_menu_entry("URL Aliases", "waliassetup",
118118
"Configure URL aliases");
119
- setup_menu_entry("Email", "setup_email", "Email notifications");
119
+ setup_menu_entry("Notification", "setup_notification",
120
+ "Automatic notifications of changes via outbound email");
121
+ setup_menu_entry("Email-Server", "setup_smtp",
122
+ "Activate and configure the built-in email server");
120123
setup_menu_entry("Transfers", "xfersetup",
121124
"Configure the transfer system for this repository");
122125
setup_menu_entry("Skins", "setup_skin",
123126
"Select and/or modify the web interface \"skins\"");
124127
setup_menu_entry("Moderation", "setup_modreq",
125128
--- src/setup.c
+++ src/setup.c
@@ -114,11 +114,14 @@
114 "Configure the trouble-ticketing system for this repository");
115 setup_menu_entry("Search","srchsetup",
116 "Configure the built-in search engine");
117 setup_menu_entry("URL Aliases", "waliassetup",
118 "Configure URL aliases");
119 setup_menu_entry("Email", "setup_email", "Email notifications");
 
 
 
120 setup_menu_entry("Transfers", "xfersetup",
121 "Configure the transfer system for this repository");
122 setup_menu_entry("Skins", "setup_skin",
123 "Select and/or modify the web interface \"skins\"");
124 setup_menu_entry("Moderation", "setup_modreq",
125
--- src/setup.c
+++ src/setup.c
@@ -114,11 +114,14 @@
114 "Configure the trouble-ticketing system for this repository");
115 setup_menu_entry("Search","srchsetup",
116 "Configure the built-in search engine");
117 setup_menu_entry("URL Aliases", "waliassetup",
118 "Configure URL aliases");
119 setup_menu_entry("Notification", "setup_notification",
120 "Automatic notifications of changes via outbound email");
121 setup_menu_entry("Email-Server", "setup_smtp",
122 "Activate and configure the built-in email server");
123 setup_menu_entry("Transfers", "xfersetup",
124 "Configure the transfer system for this repository");
125 setup_menu_entry("Skins", "setup_skin",
126 "Select and/or modify the web interface \"skins\"");
127 setup_menu_entry("Moderation", "setup_modreq",
128
+26 -8
--- src/smtp.c
+++ src/smtp.c
@@ -20,21 +20,20 @@
2020
*/
2121
#include "config.h"
2222
#include "smtp.h"
2323
#include <assert.h>
2424
25
+#ifdef __linux__
26
+# define FOSSIL_ENABLE_DNS_LOOKUP
27
+#endif
2528
26
-#if !defined(FOSSIL_OMIT_SMTP)
27
-#if defined(_WIN32)
28
- /* Don't yet know how to do this on windows */
29
-#else
29
+#if defined(FOSSIL_ENABLE_DNS_LOOKUP)
3030
# include <sys/types.h>
3131
# include <netinet/in.h>
3232
# include <arpa/nameser.h>
3333
# include <resolv.h>
34
-#endif
35
-#endif /* !defined(FOSSIL_OMIT_SMTP) */
34
+#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
3635
3736
3837
/*
3938
** Find the hostname for receiving email for the domain given
4039
** in zDomain. Return NULL if not found or not implemented.
@@ -43,11 +42,11 @@
4342
**
4443
** The returned string is obtained from fossil_malloc()
4544
** and should be released using fossil_free().
4645
*/
4746
char *smtp_mx_host(const char *zDomain){
48
-#if !defined(_WIN32) && !defined(FOSSIL_OMIT_SMTP)
47
+#if defined(FOSSIL_ENABLE_DNS_LOOKUP)
4948
int nDns; /* Length of the DNS reply */
5049
int rc; /* Return code from various APIs */
5150
int i; /* Loop counter */
5251
int iBestPriority = 9999999; /* Best priority */
5352
int nRec; /* Number of answers */
@@ -81,11 +80,11 @@
8180
if( pBest ){
8281
ns_name_uncompress(aDns, aDns+nDns, pBest+2,
8382
zHostname, sizeof(zHostname));
8483
return fossil_strdup(zHostname);
8584
}
86
-#endif /* not windows */
85
+#endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
8786
return 0;
8887
}
8988
9089
/*
9190
** COMMAND: test-find-mx
@@ -670,10 +669,29 @@
670669
}
671670
if( eForce==1 || !db_table_exists("repository","emailblob") ){
672671
db_multi_exec(zEmailSchema/*works-like:""*/);
673672
}
674673
}
674
+
675
+/*
676
+** WEBPAGE: setup_smtp
677
+**
678
+** Administrative page for configuring and controlling inbound email and
679
+** output email queuing. This page is available to administrators
680
+** only via the /Admin/EmailServer menu.
681
+*/
682
+void setup_smtp(void){
683
+ login_check_credentials();
684
+ if( !g.perm.Setup ){
685
+ login_needed(0);
686
+ return;
687
+ }
688
+ style_header("Email Server Setup");
689
+ @ <i>Pending...</i>
690
+ style_footer();
691
+}
692
+
675693
676694
#if LOCAL_INTERFACE
677695
/*
678696
** State information for the server
679697
*/
680698
--- src/smtp.c
+++ src/smtp.c
@@ -20,21 +20,20 @@
20 */
21 #include "config.h"
22 #include "smtp.h"
23 #include <assert.h>
24
 
 
 
25
26 #if !defined(FOSSIL_OMIT_SMTP)
27 #if defined(_WIN32)
28 /* Don't yet know how to do this on windows */
29 #else
30 # include <sys/types.h>
31 # include <netinet/in.h>
32 # include <arpa/nameser.h>
33 # include <resolv.h>
34 #endif
35 #endif /* !defined(FOSSIL_OMIT_SMTP) */
36
37
38 /*
39 ** Find the hostname for receiving email for the domain given
40 ** in zDomain. Return NULL if not found or not implemented.
@@ -43,11 +42,11 @@
43 **
44 ** The returned string is obtained from fossil_malloc()
45 ** and should be released using fossil_free().
46 */
47 char *smtp_mx_host(const char *zDomain){
48 #if !defined(_WIN32) && !defined(FOSSIL_OMIT_SMTP)
49 int nDns; /* Length of the DNS reply */
50 int rc; /* Return code from various APIs */
51 int i; /* Loop counter */
52 int iBestPriority = 9999999; /* Best priority */
53 int nRec; /* Number of answers */
@@ -81,11 +80,11 @@
81 if( pBest ){
82 ns_name_uncompress(aDns, aDns+nDns, pBest+2,
83 zHostname, sizeof(zHostname));
84 return fossil_strdup(zHostname);
85 }
86 #endif /* not windows */
87 return 0;
88 }
89
90 /*
91 ** COMMAND: test-find-mx
@@ -670,10 +669,29 @@
670 }
671 if( eForce==1 || !db_table_exists("repository","emailblob") ){
672 db_multi_exec(zEmailSchema/*works-like:""*/);
673 }
674 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
676 #if LOCAL_INTERFACE
677 /*
678 ** State information for the server
679 */
680
--- src/smtp.c
+++ src/smtp.c
@@ -20,21 +20,20 @@
20 */
21 #include "config.h"
22 #include "smtp.h"
23 #include <assert.h>
24
25 #ifdef __linux__
26 # define FOSSIL_ENABLE_DNS_LOOKUP
27 #endif
28
29 #if defined(FOSSIL_ENABLE_DNS_LOOKUP)
 
 
 
30 # include <sys/types.h>
31 # include <netinet/in.h>
32 # include <arpa/nameser.h>
33 # include <resolv.h>
34 #endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
 
35
36
37 /*
38 ** Find the hostname for receiving email for the domain given
39 ** in zDomain. Return NULL if not found or not implemented.
@@ -43,11 +42,11 @@
42 **
43 ** The returned string is obtained from fossil_malloc()
44 ** and should be released using fossil_free().
45 */
46 char *smtp_mx_host(const char *zDomain){
47 #if defined(FOSSIL_ENABLE_DNS_LOOKUP)
48 int nDns; /* Length of the DNS reply */
49 int rc; /* Return code from various APIs */
50 int i; /* Loop counter */
51 int iBestPriority = 9999999; /* Best priority */
52 int nRec; /* Number of answers */
@@ -81,11 +80,11 @@
80 if( pBest ){
81 ns_name_uncompress(aDns, aDns+nDns, pBest+2,
82 zHostname, sizeof(zHostname));
83 return fossil_strdup(zHostname);
84 }
85 #endif /* defined(FOSSIL_ENABLE_DNS_LOOKUP) */
86 return 0;
87 }
88
89 /*
90 ** COMMAND: test-find-mx
@@ -670,10 +669,29 @@
669 }
670 if( eForce==1 || !db_table_exists("repository","emailblob") ){
671 db_multi_exec(zEmailSchema/*works-like:""*/);
672 }
673 }
674
675 /*
676 ** WEBPAGE: setup_smtp
677 **
678 ** Administrative page for configuring and controlling inbound email and
679 ** output email queuing. This page is available to administrators
680 ** only via the /Admin/EmailServer menu.
681 */
682 void setup_smtp(void){
683 login_check_credentials();
684 if( !g.perm.Setup ){
685 login_needed(0);
686 return;
687 }
688 style_header("Email Server Setup");
689 @ <i>Pending...</i>
690 style_footer();
691 }
692
693
694 #if LOCAL_INTERFACE
695 /*
696 ** State information for the server
697 */
698
+21 -3
--- src/webmail.c
+++ src/webmail.c
@@ -34,10 +34,11 @@
3434
*/
3535
void webmail_page(void){
3636
int emailid;
3737
Stmt q;
3838
Blob sql;
39
+ int showAll = 0;
3940
login_check_credentials();
4041
if( g.zLogin==0 ){
4142
login_needed(0);
4243
return;
4344
}
@@ -70,15 +71,28 @@
7071
db_finalize(&q);
7172
}
7273
style_header("Webmail");
7374
blob_init(&sql, 0, 0);
7475
blob_append_sql(&sql,
75
- /* 0 1 2 3 4 */
76
- "SELECT efrom, datetime(edate,'unixepoch'), estate, esubject, emsgid"
76
+ /* 0 1 2 3 4 5 */
77
+ "SELECT efrom, datetime(edate,'unixepoch'), estate, esubject, emsgid, euser"
7778
" FROM emailbox"
7879
);
79
- if( !g.perm.Admin || P("all")==0 ){
80
+ if( g.perm.Admin ){
81
+ const char *zUser = P("user");
82
+ if( P("all")!=0 ){
83
+ /* Show all email messages */
84
+ showAll = 1;
85
+ }else{
86
+ style_submenu_element("All", "%R/webmail?all");
87
+ if( zUser ){
88
+ blob_append_sql(&sql, " WHERE euser=%Q", zUser);
89
+ }else{
90
+ blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin);
91
+ }
92
+ }
93
+ }else{
8094
blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin);
8195
}
8296
blob_append_sql(&sql, " ORDER BY edate DESC limit 50");
8397
db_prepare_blob(&q, &sql);
8498
blob_reset(&sql);
@@ -87,12 +101,16 @@
87101
int emailid = db_column_int(&q,4);
88102
const char *zFrom = db_column_text(&q, 0);
89103
const char *zDate = db_column_text(&q, 1);
90104
const char *zSubject = db_column_text(&q, 3);
91105
@ <li>
106
+ if( showAll ){
107
+ const char *zTo = db_column_text(&q,5);
108
+ @ <a href="%R/webmail?user=%t(zTo)">%h(zTo)</a>:
109
+ }
92110
@ <a href="%R/webmail?id=%d(emailid)">%h(zFrom) &rarr; %h(zSubject)</a>
93111
@ %h(zDate)
94112
}
95113
db_finalize(&q);
96114
@ </ol>
97115
style_footer();
98116
}
99117
--- src/webmail.c
+++ src/webmail.c
@@ -34,10 +34,11 @@
34 */
35 void webmail_page(void){
36 int emailid;
37 Stmt q;
38 Blob sql;
 
39 login_check_credentials();
40 if( g.zLogin==0 ){
41 login_needed(0);
42 return;
43 }
@@ -70,15 +71,28 @@
70 db_finalize(&q);
71 }
72 style_header("Webmail");
73 blob_init(&sql, 0, 0);
74 blob_append_sql(&sql,
75 /* 0 1 2 3 4 */
76 "SELECT efrom, datetime(edate,'unixepoch'), estate, esubject, emsgid"
77 " FROM emailbox"
78 );
79 if( !g.perm.Admin || P("all")==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
80 blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin);
81 }
82 blob_append_sql(&sql, " ORDER BY edate DESC limit 50");
83 db_prepare_blob(&q, &sql);
84 blob_reset(&sql);
@@ -87,12 +101,16 @@
87 int emailid = db_column_int(&q,4);
88 const char *zFrom = db_column_text(&q, 0);
89 const char *zDate = db_column_text(&q, 1);
90 const char *zSubject = db_column_text(&q, 3);
91 @ <li>
 
 
 
 
92 @ <a href="%R/webmail?id=%d(emailid)">%h(zFrom) &rarr; %h(zSubject)</a>
93 @ %h(zDate)
94 }
95 db_finalize(&q);
96 @ </ol>
97 style_footer();
98 }
99
--- src/webmail.c
+++ src/webmail.c
@@ -34,10 +34,11 @@
34 */
35 void webmail_page(void){
36 int emailid;
37 Stmt q;
38 Blob sql;
39 int showAll = 0;
40 login_check_credentials();
41 if( g.zLogin==0 ){
42 login_needed(0);
43 return;
44 }
@@ -70,15 +71,28 @@
71 db_finalize(&q);
72 }
73 style_header("Webmail");
74 blob_init(&sql, 0, 0);
75 blob_append_sql(&sql,
76 /* 0 1 2 3 4 5 */
77 "SELECT efrom, datetime(edate,'unixepoch'), estate, esubject, emsgid, euser"
78 " FROM emailbox"
79 );
80 if( g.perm.Admin ){
81 const char *zUser = P("user");
82 if( P("all")!=0 ){
83 /* Show all email messages */
84 showAll = 1;
85 }else{
86 style_submenu_element("All", "%R/webmail?all");
87 if( zUser ){
88 blob_append_sql(&sql, " WHERE euser=%Q", zUser);
89 }else{
90 blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin);
91 }
92 }
93 }else{
94 blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin);
95 }
96 blob_append_sql(&sql, " ORDER BY edate DESC limit 50");
97 db_prepare_blob(&q, &sql);
98 blob_reset(&sql);
@@ -87,12 +101,16 @@
101 int emailid = db_column_int(&q,4);
102 const char *zFrom = db_column_text(&q, 0);
103 const char *zDate = db_column_text(&q, 1);
104 const char *zSubject = db_column_text(&q, 3);
105 @ <li>
106 if( showAll ){
107 const char *zTo = db_column_text(&q,5);
108 @ <a href="%R/webmail?user=%t(zTo)">%h(zTo)</a>:
109 }
110 @ <a href="%R/webmail?id=%d(emailid)">%h(zFrom) &rarr; %h(zSubject)</a>
111 @ %h(zDate)
112 }
113 db_finalize(&q);
114 @ </ol>
115 style_footer();
116 }
117

Keyboard Shortcuts

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