/************************************************************************************************** $Header: /pub/cvsroot/yencode/src/ypost/usenet.c,v 1.1 2002/03/15 15:10:49 bboy Exp $ Routines used by `ypost' to validate and construct Usenet (RFC 1036) data. Copyright (C) 2002 Don Moore This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at Your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA **************************************************************************************************/ #include "ypost.h" /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ VALIDATE_EMAIL Is this a valid email address? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ static char * validate_email(char *email) { /* XXX: This is VERY non-robust */ if (strchr(email, '@')) return (NULL); else return (_("invalid email address")); } /*--- validate_email() --------------------------------------------------------------------------*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ USENET_VALID_FROM Checks the supplied address to make sure it's a conformant From: value. Will make minor adjustments to the string if possible. Returns NULL if conformant, or a string describing the problem if not. This function is not that strict. RFC 1036 gives the following examples as valid addresses: From: mark@cbosgd.ATT.COM From: mark@cbosgd.ATT.COM (Mark Horton) From: Mark Horton +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ char * usenet_valid_From(char *from, size_t len) { char *paren, *angle, *email, *comment, *reason; char fromcopy[BUFSIZ]; strtrim(from); strncpy(fromcopy, from, sizeof(fromcopy)-1); paren = strchr(fromcopy, '('); angle = strchr(fromcopy, '<'); // First form: No parens, no angle brackets if (!paren && !angle) { email = fromcopy; opt_sender = xstrdup(email); strtrim(opt_sender); return (validate_email(email)); } // Second form: Comment in parentheses if (paren) { email = fromcopy; comment = paren; *(comment++) = '\0'; if (!(paren = strchr(comment, ')'))) return (_("unterminated comment in author name")); *paren = '\0'; opt_sender = xstrdup(email); strtrim(opt_sender); if ((reason = validate_email(email))) return (reason); return (NULL); } // Third form: Email in angle brackets if (angle) { comment = fromcopy; email = angle; *(email++) = '\0'; if (!(angle = strchr(email, '>'))) return (_("unterminated email address in author name")); *angle = '\0'; opt_sender = xstrdup(email); strtrim(opt_sender); if ((reason = validate_email(email))) return (reason); return (NULL); } return (_("unknown or invalid format for author (see ypost(1))")); } /*--- usenet_valid_From() -----------------------------------------------------------------------*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ USENET_VALID_SUBJECT Checks the supplied subject data to make sure it's a conformant Subject: value. Returns NULL if conformant, or a string describing the problem if not. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ char * usenet_valid_Subject(char *str, size_t len) { strtrim(str); /* XXX: This isn't much of a check! */ return (NULL); } /*--- usenet_valid_Subject() --------------------------------------------------------------------*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ USENET_DATE Returns a static string containing the date in the format specified by RFC 822 / RFC 1036 Ex: Wdy, DD Mon YY HH:MM:SS TIMEZONE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ char * usenet_date(void) { static char datebuf[80]; /* Return value */ time_t now; /* Current time */ const struct tm *tm; /* Broken down time */ time(&now); tm = gmtime(&now); strftime(datebuf, sizeof(datebuf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); return (datebuf); } /*--- usenet_date() -----------------------------------------------------------------------------*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ USENET_MESSAGE_ID Returns an unique message ID. The basic format is: