00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "services.h"
00016 #include "language.h"
00017
00018
00019
00030 MailInfo *MailRegBegin(User * u, NickRequest * nr, char *subject,
00031 char *service)
00032 {
00033 if (!u || !nr || !subject || !service) {
00034 return NULL;
00035 }
00036
00037 if (!UseMail) {
00038 notice_lang(service, u, MAIL_DISABLED);
00039 } else if ((time(NULL) - u->lastmail < MailDelay)
00040 || (time(NULL) - nr->lastmail < MailDelay)) {
00041 notice_lang(service, u, MAIL_DELAYED, MailDelay);
00042 } else if (!nr->email) {
00043 notice_lang(service, u, MAIL_INVALID, nr->nick);
00044 } else {
00045 MailInfo *mail;
00046
00047 mail = scalloc(sizeof(MailInfo), 1);
00048 mail->sender = u;
00049 mail->recipient = NULL;
00050 mail->recip = nr;
00051
00052 if (!(mail->pipe = popen(SendMailPath, "w"))) {
00053 free(mail);
00054 notice_lang(service, u, MAIL_LATER);
00055 return NULL;
00056 }
00057
00058 fprintf(mail->pipe, "From: %s\n", SendFrom);
00059 if (DontQuoteAddresses) {
00060 fprintf(mail->pipe, "To: %s <%s>\n", nr->nick, nr->email);
00061 } else {
00062 fprintf(mail->pipe, "To: \"%s\" <%s>\n", nr->nick, nr->email);
00063 }
00064 fprintf(mail->pipe, "Subject: %s\n", subject);
00065 return mail;
00066 }
00067
00068 return NULL;
00069 }
00070
00071
00072
00083 MailInfo *MailBegin(User * u, NickCore * nc, char *subject, char *service)
00084 {
00085 if (!u || !nc || !subject || !service) {
00086 return NULL;
00087 }
00088
00089 if (!UseMail) {
00090 notice_lang(service, u, MAIL_DISABLED);
00091 } else if (((time(NULL) - u->lastmail < MailDelay)
00092 || (time(NULL) - nc->lastmail < MailDelay))
00093 && !is_services_root(u)) {
00094 notice_lang(service, u, MAIL_DELAYED, MailDelay);
00095 } else if (!nc->email) {
00096 notice_lang(service, u, MAIL_INVALID, nc->display);
00097 } else {
00098 MailInfo *mail;
00099
00100 mail = scalloc(sizeof(MailInfo), 1);
00101 mail->sender = u;
00102 mail->recipient = nc;
00103 mail->recip = NULL;
00104
00105 if (!(mail->pipe = popen(SendMailPath, "w"))) {
00106 free(mail);
00107 notice_lang(service, u, MAIL_LATER);
00108 return NULL;
00109 }
00110
00111 fprintf(mail->pipe, "From: %s\n", SendFrom);
00112 if (DontQuoteAddresses) {
00113 fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email);
00114 } else {
00115 fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display,
00116 nc->email);
00117 }
00118 fprintf(mail->pipe, "Subject: %s\n", subject);
00119
00120 return mail;
00121 }
00122
00123 return NULL;
00124 }
00125
00126
00127
00133 MailInfo *MailMemoBegin(NickCore * nc)
00134 {
00135
00136 if (!nc)
00137 return NULL;
00138
00139 if (!UseMail || !nc->email) {
00140 return NULL;
00141
00142 } else {
00143 MailInfo *mail;
00144
00145 mail = scalloc(sizeof(MailInfo), 1);
00146 mail->sender = NULL;
00147 mail->recipient = nc;
00148 mail->recip = NULL;
00149
00150 if (!(mail->pipe = popen(SendMailPath, "w"))) {
00151 free(mail);
00152 return NULL;
00153 }
00154
00155 fprintf(mail->pipe, "From: %s\n", SendFrom);
00156 if (DontQuoteAddresses) {
00157 fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email);
00158 } else {
00159 fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display,
00160 nc->email);
00161 }
00162 fprintf(mail->pipe, "Subject: %s\n",
00163 getstring2(NULL, MEMO_MAIL_SUBJECT));
00164 return mail;
00165 }
00166 return NULL;
00167 }
00168
00169
00170
00176 void MailEnd(MailInfo * mail)
00177 {
00178
00179
00180
00181
00182 if (!mail || !mail->pipe) {
00183 return;
00184 }
00185
00186 if (!mail->recipient && !mail->recip) {
00187 return;
00188 }
00189
00190 pclose(mail->pipe);
00191
00192 if (mail->sender)
00193 mail->sender->lastmail = time(NULL);
00194
00195 if (mail->recipient)
00196 mail->recipient->lastmail = time(NULL);
00197 else
00198 mail->recip->lastmail = time(NULL);
00199
00200
00201 free(mail);
00202 }
00203
00204
00205
00212 void MailReset(User * u, NickCore * nc)
00213 {
00214 if (u)
00215 u->lastmail = 0;
00216 if (nc)
00217 nc->lastmail = 0;
00218 }
00219
00220
00221
00232 int MailValidate(const char *email)
00233 {
00234 int i, j, has_period = 0, len;
00235 char copy[BUFSIZE], *domain;
00236
00237 static char specials[] =
00238 { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']',
00239 ' '
00240 };
00241
00242 if (!email)
00243 return 0;
00244 strcpy(copy, email);
00245
00246 domain = strchr(copy, '@');
00247 if (!domain)
00248 return 0;
00249 *domain = '\0';
00250 domain++;
00251
00252
00253 if (*copy == 0 || *domain == 0)
00254 return 0;
00255
00256
00257 for (i = 0; i < strlen(copy); i++) {
00258
00259 if (copy[i] <= 31 || copy[i] >= 127)
00260 return 0;
00261 for (j = 0; j < 13; j++)
00262 if (copy[i] == specials[j])
00263 return 0;
00264 }
00265
00266
00267 for (i = 0; i < (len = strlen(domain)); i++) {
00268 if (domain[i] <= 31 || domain[i] >= 127)
00269 return 0;
00270 for (j = 0; j < 13; j++)
00271 if (domain[i] == specials[j])
00272 return 0;
00273 if (domain[i] == '.') {
00274 if (i == 0 || i == len - 1)
00275 return 0;
00276 has_period = 1;
00277 }
00278 }
00279
00280 if (!has_period)
00281 return 0;
00282
00283 return 1;
00284 }