2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: DmxUtils.C /main/3 1996/04/21 19:55:51 drk $ */
30 * RESTRICTED CONFIDENTIAL INFORMATION:
32 * The information in this document is subject to special
33 * restrictions in a confidential disclosure agreement between
34 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
35 * document outside HP, IBM, Sun, USL, SCO, or Univel without
36 * Sun's specific written approval. This document and all copies
37 * and derivative works thereof must be returned or destroyed at
40 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
45 * Common Desktop Environment
47 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
48 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
49 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
50 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51 * (c) Copyright 1995 Digital Equipment Corp.
52 * (c) Copyright 1995 Fujitsu Limited
53 * (c) Copyright 1995 Hitachi, Ltd.
56 * RESTRICTED RIGHTS LEGEND
58 *Use, duplication, or disclosure by the U.S. Government is subject to
59 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
60 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
61 *for non-DOD U.S. Government Departments and Agencies are as set forth in
62 *FAR 52.227-19(c)(1,2).
64 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
65 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
66 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
67 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
68 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
69 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
70 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
75 // fn proto for mailx fn
76 static char * dispname(const char *hdr);
78 // error-handling: should do something with minor codes
81 handleError (DtMailEnv &dterror, char *msg)
83 if (dterror.isSet () == DTM_TRUE)
85 fprintf (stderr, "dtmailpr: (%s) %s\n",
86 msg, (const char *)dterror);
87 dterror.logError (DTM_FALSE, "dtmailpr: (%s) %s\n",
88 msg, (const char *)dterror);
100 errorString (DmxHeaders hdr)
107 return "(no subject)";
113 return "(unknown date)";
123 getStandardHeaders (DtMailHeaderLine &info)
125 int i = 0, length = 0;
129 const char *header [DMXNUMHDRS];
131 for (i = 0; i < DMXNUMHDRS; i++)
133 length = info.header_values[i].length ();
136 header [i] = errorString ((DmxHeaders) i);
138 header [i] = *((info.header_values[i])[0]);
142 for (i = 0; i < DMXNUMHDRS; i++)
144 buflength += strlen (header [i]);
147 fbuf = new char [buflength + 64];
150 "From: %s\nDate: %s\nTo: %s\nSubject: %s\n",
151 dispname (header [DMXFROM]),
156 return (fbuf); //need to free this after using it
159 // stuff grabbed from mailx...it's ugly, but it looks pretty
161 #define NOSTR ((char *) 0) /* Nill string pointer */
162 #define LINESIZE 5120 /* max readable line width */
163 static char *phrase(char *, int , int );
166 * Return a pointer to a dynamic copy of the argument.
168 // changed salloc to malloc
172 register char *cp, *cp2, *top;
174 for (cp = str; *cp; cp++)
176 top = (char *)malloc((unsigned)(cp-str + 1));
179 for (cp = str, cp2 = top; *cp; cp++)
189 return phrase(name, 0, 0);
192 * Return the full name from an RFC-822 header line
193 * or the last two (or one) component of the address.
197 dispname(const char *hdr)
198 // made it a const char * instead of a char *
204 if (((cp = const_cast <char *> (strchr(hdr, '<'))) != 0) && (cp > hdr)) {
206 if ((*hdr == '"') && ((cp = const_cast <char *> (strrchr(++hdr, '"'))) != 0))
209 } else if ((cp = const_cast <char *> (strchr(hdr, '('))) != 0) {
211 if ((cp = const_cast <char *> (strchr(hdr, '+'))) != 0)
213 if ((cp = const_cast <char *> (strrchr(hdr, ')'))) != 0)
217 cp = skin((char *)hdr);
218 if ((cp2 = strrchr(cp, '!')) != 0) {
219 while (cp2 >= cp && *--cp2 != '!');
226 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
229 * Skin an arpa net address according to the RFC 822 interpretation
232 // changed salloc to malloc
234 phrase(char *name, int token, int comma)
237 register char *cp, *cp2;
238 char *bufend, *nbufp;
239 int gotlt, lastsp, didq;
245 if (strlen(name) >= (unsigned)LINESIZE)
246 nbufp = (char *)malloc(strlen(name));
252 for (cp = name, cp2 = bufend; (c = *cp++) != 0;) {
256 Start of a comment, ignore it.
259 while ((c = *cp) != 0) {
263 if (*cp == 0) goto outcm;
273 if (nesting <= 0) break;
280 Start a quoted string.
281 Copy it in its entirety.
284 while ((c = *cp) != 0) {
288 if ((c = *cp) == 0) goto outqs;
294 if (gotlt == 0 || gotlt == '<') {
315 if (token && (!comma || c == '\n')) {
345 /* FALLTHROUGH . . . */
348 if (gotlt == 0 || gotlt == '<') {
359 return (token ? --cp : equal(name, nbufp) ? name :
360 nbufp == nbuf ? savestr(nbuf) : nbufp);