4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
31 #define MAXHDRSIZE 100 /* Maximum length of header line */
32 #define MAXUNAME 20 /* Maximum length of user name */
35 * display headers, indicating current and status
37 * current is the displacement into the mailfile of the
40 * all indicates how many headers should be shown.
41 * 0 -> show window +/-6 around current
42 * 1 -> show all messages
43 * 2 -> show deleted messages
45 * Only 100 characters of the From (first) header line will
46 * be read in. This line is assumed to be in the following
48 * From <sender address> <date>
50 * <sender address> is either a UUCP-style (sysa!sysb!user)
51 * or domain-style address (user@host).
53 * If the sender address contains a UUCP-style address, then
54 * the user name displayed is made up of the characters following
55 * the final '!' in the sender address, otherwise the sender
56 * address is considered to be the user name.
58 * The maximum number of characters of a user name displayed
63 gethead(int current
, int all
)
69 char holdval
[MAXHDRSIZE
];
71 char wlineval
[MAXHDRSIZE
];
74 int rc
, size
, start
, stop
, ix
;
75 char userval
[MAXUNAME
];
78 int unamechars
= MAXUNAME
- 1;
84 printf("%d letters found in %s, %d scheduled for deletion, "
85 "%d newly arrived\n", nlet
, mailfile
, changed
, nlet
- onlet
);
87 if (all
== 2 && !changed
)
90 file
= doopen(lettmp
, "r", E_TMP
);
93 if (stop
< -1) stop
= -1;
95 if (start
> nlet
- 1) start
= nlet
- 1;
102 if (stop
> nlet
) stop
= nlet
;
104 if (start
< 0) start
= 0;
110 for (ln
= start
; ln
!= stop
; ln
= flgr
? ln
+ 1 : ln
- 1) {
111 size
= let
[ln
+1].adr
- let
[ln
].adr
;
112 if ((rc
= fseek(file
, let
[ln
].adr
, 0)) != 0) {
113 errmsg(E_FILE
, "Cannot seek header");
117 if (fgets(wline
, MAXHDRSIZE
, file
) == NULL
) {
118 errmsg(E_FILE
, "Cannot read header");
122 if ((rc
= strncmp(wline
, header
[H_FROM
].tag
, 5)) != SAME
) {
123 errmsg(E_FILE
, "Invalid header encountered");
128 /* skip past trailing white space after header tag */
129 for (rc
= 5; wline
[rc
] == ' ' || wline
[rc
] == '\t'; ++rc
)
131 (void) strlcpy(hold
, wline
+ rc
, MAXHDRSIZE
);
132 fgets(wline
, MAXHDRSIZE
, file
);
134 while (((rc
= strncmp(wline
,
135 header
[H_FROM1
].tag
, 6)) == SAME
) &&
136 (substr(wline
, "remote from ") != -1)) {
137 (void) strlcpy(hold
, wline
+ 6, MAXHDRSIZE
);
138 fgets(wline
, MAXHDRSIZE
, file
);
143 * If UUCP-style sender address, then read past
144 * last "!" to get the start of the user name.
146 sender_size
= strcspn(hold
, " \t");
148 if ((uucpptr
= strrchr(hold
, '!')) != NULL
) {
149 uucpstart
= uucpptr
- hold
+ 1;
150 if (uucpstart
> sender_size
) {
155 /* Get the user name out of the sender address. */
156 for (ix
= 0, rc
= uucpstart
; ix
< unamechars
&&
157 hold
[rc
] != ' ' && hold
[rc
] != '\t' &&
158 rc
< sender_size
; ++rc
) {
159 userval
[ix
++] = hold
[rc
];
161 if ((ix
> 0) && (userval
[ix
- 1] == '\n')) {
162 userval
[ix
- 1] = '\0';
168 * Skip past the rest of the sender address, and
169 * delimiting white space.
171 for (; hold
[rc
] != '\0' && hold
[rc
] != ' ' &&
172 hold
[rc
] != '\t'; ++rc
)
174 for (; hold
[rc
] == ' ' || hold
[rc
] == '\t'; ++rc
)
177 /* Get the date information. */
178 (void) strlcpy(wline
, hold
+ rc
, MAXHDRSIZE
);
179 for (rc
= 0; wline
[rc
] != '\0' && wline
[rc
] != '\n'; ++rc
)
183 if (!flgh
&& current
== ln
) mark
= '>';
187 if (displayed
>= changed
) {
191 if (let
[ln
].change
== ' ') continue;
194 printf("%c %3d %c %-5d %-10s %s\n", mark
, ln
+ 1,
195 let
[ln
].change
, size
, userval
, wline
);
210 * Write a string out to tmp file, with error checking.
211 * Return 1 on success, else 0
214 wtmpf(char *str
, int length
)
216 if (fwrite(str
, 1, length
, tmpf
) != length
) {
224 * Read a line from stdin, assign it to line and
225 * return number of bytes in length
228 getaline(char *ptr2line
, int max
, FILE *f
)
231 for (i
= 0; i
< max
-1 && (ch
= getc(f
)) != EOF
; )
232 if ((ptr2line
[i
++] = ch
) == '\n') break;
238 * Make temporary file for letter
243 static char tmpl
[] = "/var/tmp/mailXXXXXX";
244 int fd
= mkstemp(lettmp
= tmpl
);
246 if (fd
< 0 || (tmpf
= fdopen(fd
, "w+")) == NULL
) {
248 "%s: Can't open '%s', type: w+\n", program
, lettmp
);
254 * Get a number from user's reply,
255 * return its value or zero if none present, -1 on error
262 while (*s
== ' ' || *s
== '\t') s
++;
265 if ((k
= atoi(s
)) != 0)
269 for (; *s
>= '0' && *s
<= '9'; ) s
++;
270 if (*s
!= '\0' && *s
!= '\n') {
271 printf("Illegal numeric\n");
280 * If valid msgnum return 1,
281 * else print message and return 0
286 if ((i
< 0) || (i
> nlet
)) {
287 printf("No such message\n");
294 * Set letter to passed status, and adjust changed as necessary
297 setletr(int letter
, int status
)
300 if (let
[letter
].change
!= ' ')
301 if (changed
) changed
--;
303 if (let
[letter
].change
== ' ') changed
++;
305 let
[letter
].change
= status
;