1c89f78d29754be687dde409ae19b4e743f85703
chinhli
  Fri Apr 5 10:43:10 2013 -0700
redmine #9752 #8920 A more secure and sharable sendmail utility mailViaPipe for hgLogin
diff --git src/lib/mailViaPipe.c src/lib/mailViaPipe.c
new file mode 100644
index 0000000..dd54041
--- /dev/null
+++ src/lib/mailViaPipe.c
@@ -0,0 +1,27 @@
+/* mailViaPipe - a safer and sharable sendmail utility using
+ * more secure pipeline module.
+ * Special note: 
+ * Currently, RR never return exit or error status to the browser 
+ * after sendmail, so the implementation here does not handle any 
+ * error condition at all, and will return 0 regardless. */
+ 
+#include "pipeline.h"
+#include "common.h"
+#include "mailViaPipe.h"
+
+int mailViaPipe(char *toAddress, char *theSubject, char *theBody, char *fromAddress)
+{
+char *cmd1[] = {"/usr/sbin/sendmail", "-t", "-oi", NULL};
+struct pipeline *dataPipe = pipelineOpen1(cmd1, pipelineWrite | pipelineNoAbort,
+"/dev/null", NULL);
+FILE *out = pipelineFile(dataPipe);
+fprintf(out, "To: %s\n", toAddress);
+fprintf(out, "From: %s\n", fromAddress);
+fprintf(out, "Subject: %s\n", theSubject);
+fprintf(out, "%s\n", theBody);
+fflush(out);
+if(ferror(out) || pipelineWait(dataPipe))
+    pipelineFree(&dataPipe);
+return 0;
+}
+