00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <string.h>
00046
00047 #include "email.h"
00048 #include "options.h"
00049
00059 const char *EmailString::set_string(const char *str)
00060 {
00061 int len;
00062
00063 if (theString)
00064 delete theString;
00065 if (!str)
00066 return (theString = NULL);
00067
00068 theString = new char[(len = strlen(str)) + 1];
00069 strcpy(theString, str);
00070 theLength = 0;
00071
00072 if (!theString) {
00073 fprintf(stderr, "Out of memory!\n");
00074 abort();
00075 return theString;
00076 }
00077 theLength = len;
00078 return theString;
00079 }
00080
00086 const char *EmailString::add(const char *str)
00087 {
00088 int len;
00089
00090 if (!str)
00091 return NULL;
00092 len = strlen(str);
00093
00094 if (!theString) {
00095 theString = new char[len + 1];
00096 if (!theString) {
00097 fprintf(stderr, "Out of memory!\n");
00098 abort();
00099 return str;
00100 }
00101 strcpy(theString, str);
00102 theLength = len;
00103 return str;
00104 }
00105
00106 theString =
00107 static_cast<char *>(realloc(theString, len + theLength + 1));
00108 strcat(theString + theLength, str);
00109 theLength += len;
00110 return theString;
00111 }
00112
00119 const char *EmailAddressBuf::add_email(const char *str)
00120 {
00121 int len;
00122
00123 if (!str)
00124 return NULL;
00125 len = strlen(str);
00126
00127 if (!theString) {
00128 theString = new char[len + 1];
00129 if (!theString) {
00130 fprintf(stderr, "Out of memory!\n");
00131 abort();
00132 return str;
00133 }
00134 strcpy(theString, str);
00135 theLength = len;
00136 return str;
00137 }
00138
00139 theString =
00140 static_cast<char *>(realloc(theString, len + theLength + 3));
00141 strcat(theString + theLength, ", ");
00142 strcat(theString + theLength + 2, str);
00143 theLength += len + 2;
00144 return theString;
00145 }
00146
00147
00154 void EmailMessage::send()
00155 {
00156 FILE *p;
00157
00158 if (!to.get_string() || !from.get_string() || !body.get_string()) {
00159 fprintf(stderr, "EmailMessage::send(): Failed.");
00160 return;
00161 }
00162
00163 p = popen(SENDMAIL, "w");
00164 if (p == NULL)
00165 return;
00166
00167 fprintf(p, "To: %s\n"
00168 "From: %s\n"
00169 "Subject: %s\n",
00170 to.get_string(), from.get_string(), subject.get_string()? subject.
00171 get_string() : "[services] No subject");
00172
00173 fputs(body.get_string(), p);
00174 fflush(p);
00175 pclose(p);
00176 }