diff options
Diffstat (limited to 'src/mail.c')
-rw-r--r-- | src/mail.c | 356 |
1 files changed, 178 insertions, 178 deletions
diff --git a/src/mail.c b/src/mail.c index 0d66086c2..43d8e7845 100644 --- a/src/mail.c +++ b/src/mail.c @@ -28,44 +28,44 @@ * @return MailInfo struct */ MailInfo *MailRegBegin(User * u, NickRequest * nr, char *subject, - char *service) + char *service) { - if (!u || !nr || !subject || !service) { - return NULL; - } - - if (!UseMail) { - notice_lang(service, u, MAIL_DISABLED); - } else if ((time(NULL) - u->lastmail < MailDelay) - || (time(NULL) - nr->lastmail < MailDelay)) { - notice_lang(service, u, MAIL_DELAYED, MailDelay); - } else if (!nr->email) { - notice_lang(service, u, MAIL_INVALID, nr->nick); - } else { - MailInfo *mail; - - mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); - mail->sender = u; - mail->recipient = NULL; - mail->recip = nr; - - if (!(mail->pipe = popen(SendMailPath, "w"))) { - free(mail); - notice_lang(service, u, MAIL_LATER); - return NULL; - } - - fprintf(mail->pipe, "From: %s\n", SendFrom); - if (DontQuoteAddresses) { - fprintf(mail->pipe, "To: %s <%s>\n", nr->nick, nr->email); - } else { - fprintf(mail->pipe, "To: \"%s\" <%s>\n", nr->nick, nr->email); - } - fprintf(mail->pipe, "Subject: %s\n", subject); - return mail; - } - - return NULL; + if (!u || !nr || !subject || !service) { + return NULL; + } + + if (!UseMail) { + notice_lang(service, u, MAIL_DISABLED); + } else if ((time(NULL) - u->lastmail < MailDelay) + || (time(NULL) - nr->lastmail < MailDelay)) { + notice_lang(service, u, MAIL_DELAYED, MailDelay); + } else if (!nr->email) { + notice_lang(service, u, MAIL_INVALID, nr->nick); + } else { + MailInfo *mail; + + mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); + mail->sender = u; + mail->recipient = NULL; + mail->recip = nr; + + if (!(mail->pipe = popen(SendMailPath, "w"))) { + free(mail); + notice_lang(service, u, MAIL_LATER); + return NULL; + } + + fprintf(mail->pipe, "From: %s\n", SendFrom); + if (DontQuoteAddresses) { + fprintf(mail->pipe, "To: %s <%s>\n", nr->nick, nr->email); + } else { + fprintf(mail->pipe, "To: \"%s\" <%s>\n", nr->nick, nr->email); + } + fprintf(mail->pipe, "Subject: %s\n", subject); + return mail; + } + + return NULL; } /*************************************************************************/ @@ -82,45 +82,45 @@ MailInfo *MailRegBegin(User * u, NickRequest * nr, char *subject, */ MailInfo *MailBegin(User * u, NickCore * nc, char *subject, char *service) { - if (!u || !nc || !subject || !service) { - return NULL; - } - - if (!UseMail) { - notice_lang(service, u, MAIL_DISABLED); - } else if (((time(NULL) - u->lastmail < MailDelay) - || (time(NULL) - nc->lastmail < MailDelay)) - && !is_services_root(u)) { - notice_lang(service, u, MAIL_DELAYED, MailDelay); - } else if (!nc->email) { - notice_lang(service, u, MAIL_INVALID, nc->display); - } else { - MailInfo *mail; - - mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); - mail->sender = u; - mail->recipient = nc; - mail->recip = NULL; - - if (!(mail->pipe = popen(SendMailPath, "w"))) { - free(mail); - notice_lang(service, u, MAIL_LATER); - return NULL; - } - - fprintf(mail->pipe, "From: %s\n", SendFrom); - if (DontQuoteAddresses) { - fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email); - } else { - fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display, - nc->email); - } - fprintf(mail->pipe, "Subject: %s\n", subject); - - return mail; - } - - return NULL; + if (!u || !nc || !subject || !service) { + return NULL; + } + + if (!UseMail) { + notice_lang(service, u, MAIL_DISABLED); + } else if (((time(NULL) - u->lastmail < MailDelay) + || (time(NULL) - nc->lastmail < MailDelay)) + && !is_services_root(u)) { + notice_lang(service, u, MAIL_DELAYED, MailDelay); + } else if (!nc->email) { + notice_lang(service, u, MAIL_INVALID, nc->display); + } else { + MailInfo *mail; + + mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); + mail->sender = u; + mail->recipient = nc; + mail->recip = NULL; + + if (!(mail->pipe = popen(SendMailPath, "w"))) { + free(mail); + notice_lang(service, u, MAIL_LATER); + return NULL; + } + + fprintf(mail->pipe, "From: %s\n", SendFrom); + if (DontQuoteAddresses) { + fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email); + } else { + fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display, + nc->email); + } + fprintf(mail->pipe, "Subject: %s\n", subject); + + return mail; + } + + return NULL; } /*************************************************************************/ @@ -133,37 +133,37 @@ MailInfo *MailBegin(User * u, NickCore * nc, char *subject, char *service) MailInfo *MailMemoBegin(NickCore * nc) { - if (!nc) - return NULL; - - if (!UseMail || !nc->email) { - return NULL; - - } else { - MailInfo *mail; - - mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); - mail->sender = NULL; - mail->recipient = nc; - mail->recip = NULL; - - if (!(mail->pipe = popen(SendMailPath, "w"))) { - free(mail); - return NULL; - } - - fprintf(mail->pipe, "From: %s\n", SendFrom); - if (DontQuoteAddresses) { - fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email); - } else { - fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display, - nc->email); - } - fprintf(mail->pipe, "Subject: %s\n", - getstring2(NULL, MEMO_MAIL_SUBJECT)); - return mail; - } - return NULL; + if (!nc) + return NULL; + + if (!UseMail || !nc->email) { + return NULL; + + } else { + MailInfo *mail; + + mail = (MailInfo *)scalloc(sizeof(MailInfo), 1); + mail->sender = NULL; + mail->recipient = nc; + mail->recip = NULL; + + if (!(mail->pipe = popen(SendMailPath, "w"))) { + free(mail); + return NULL; + } + + fprintf(mail->pipe, "From: %s\n", SendFrom); + if (DontQuoteAddresses) { + fprintf(mail->pipe, "To: %s <%s>\n", nc->display, nc->email); + } else { + fprintf(mail->pipe, "To: \"%s\" <%s>\n", nc->display, + nc->email); + } + fprintf(mail->pipe, "Subject: %s\n", + getstring2(NULL, MEMO_MAIL_SUBJECT)); + return mail; + } + return NULL; } /*************************************************************************/ @@ -175,30 +175,30 @@ MailInfo *MailMemoBegin(NickCore * nc) */ void MailEnd(MailInfo * mail) { - /* - param checking modified because we don't - have an user sending this mail. - Certus, 02.04.2004 */ + /* - param checking modified because we don't + have an user sending this mail. + Certus, 02.04.2004 */ - if (!mail || !mail->pipe) { /* removed sender check */ - return; - } + if (!mail || !mail->pipe) { /* removed sender check */ + return; + } - if (!mail->recipient && !mail->recip) { - return; - } + if (!mail->recipient && !mail->recip) { + return; + } - pclose(mail->pipe); + pclose(mail->pipe); - if (mail->sender) /* added sender check */ - mail->sender->lastmail = time(NULL); + if (mail->sender) /* added sender check */ + mail->sender->lastmail = time(NULL); - if (mail->recipient) - mail->recipient->lastmail = time(NULL); - else - mail->recip->lastmail = time(NULL); + if (mail->recipient) + mail->recipient->lastmail = time(NULL); + else + mail->recip->lastmail = time(NULL); - free(mail); + free(mail); } /*************************************************************************/ @@ -211,10 +211,10 @@ void MailEnd(MailInfo * mail) */ void MailReset(User * u, NickCore * nc) { - if (u) - u->lastmail = 0; - if (nc) - nc->lastmail = 0; + if (u) + u->lastmail = 0; + if (nc) + nc->lastmail = 0; } /*************************************************************************/ @@ -231,54 +231,54 @@ void MailReset(User * u, NickCore * nc) */ int MailValidate(const char *email) { - int has_period = 0, len; - char copy[BUFSIZE], *domain; - - static char specials[] = - { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', - ' ' - }; - - if (!email) - return 0; - strcpy(copy, email); - - domain = strchr(copy, '@'); - if (!domain) - return 0; - *domain = '\0'; - domain++; - - /* Don't accept NULL copy or domain. */ - if (*copy == 0 || *domain == 0) - return 0; - - /* Check for forbidden characters in the name */ - for (unsigned int i = 0; i < strlen(copy); i++) { - - if (copy[i] <= 31 || copy[i] >= 127) - return 0; - for (unsigned int j = 0; j < 13; j++) - if (copy[i] == specials[j]) - return 0; - } - - /* Check for forbidden characters in the domain, and if it seems to be valid. */ - for (int i = 0; i < (len = strlen(domain)); i++) { - if (domain[i] <= 31 || domain[i] >= 127) - return 0; - for (unsigned int j = 0; j < 13; j++) - if (domain[i] == specials[j]) - return 0; - if (domain[i] == '.') { - if (i == 0 || i == len - 1) - return 0; - has_period = 1; - } - } - - if (!has_period) - return 0; - - return 1; + int has_period = 0, len; + char copy[BUFSIZE], *domain; + + static char specials[] = + { '(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', + ' ' + }; + + if (!email) + return 0; + strcpy(copy, email); + + domain = strchr(copy, '@'); + if (!domain) + return 0; + *domain = '\0'; + domain++; + + /* Don't accept NULL copy or domain. */ + if (*copy == 0 || *domain == 0) + return 0; + + /* Check for forbidden characters in the name */ + for (unsigned int i = 0; i < strlen(copy); i++) { + + if (copy[i] <= 31 || copy[i] >= 127) + return 0; + for (unsigned int j = 0; j < 13; j++) + if (copy[i] == specials[j]) + return 0; + } + + /* Check for forbidden characters in the domain, and if it seems to be valid. */ + for (int i = 0; i < (len = strlen(domain)); i++) { + if (domain[i] <= 31 || domain[i] >= 127) + return 0; + for (unsigned int j = 0; j < 13; j++) + if (domain[i] == specials[j]) + return 0; + if (domain[i] == '.') { + if (i == 0 || i == len - 1) + return 0; + has_period = 1; + } + } + + if (!has_period) + return 0; + + return 1; } |