1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
30*0Sstevel@tonic-gate * Use is subject to license terms.
31*0Sstevel@tonic-gate */
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include "mail.h"
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate This routine returns undeliverable mail as well as handles
36*0Sstevel@tonic-gate replying to letters
37*0Sstevel@tonic-gate */
38*0Sstevel@tonic-gate void
goback(letnum)39*0Sstevel@tonic-gate goback(letnum)
40*0Sstevel@tonic-gate int letnum;
41*0Sstevel@tonic-gate {
42*0Sstevel@tonic-gate static char pn[] = "goback";
43*0Sstevel@tonic-gate int i, w;
44*0Sstevel@tonic-gate char buf[1024], *cp, work[1024], wuser[1024];
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate * If dflag already == 1, then been here already and
48*0Sstevel@tonic-gate * having a problem delivering failure notification.
49*0Sstevel@tonic-gate * Reset dflag to 9 to avoid endless loop.....
50*0Sstevel@tonic-gate */
51*0Sstevel@tonic-gate if (dflag == 1) {
52*0Sstevel@tonic-gate dflag = 9;
53*0Sstevel@tonic-gate Dout(pn, 0, "dflag = %d\n", dflag);
54*0Sstevel@tonic-gate if (!error) {
55*0Sstevel@tonic-gate error = E_REMOTE;
56*0Sstevel@tonic-gate Dout(pn, 0, "error = %d\n", error);
57*0Sstevel@tonic-gate }
58*0Sstevel@tonic-gate }
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate if (dflag < 2) {
61*0Sstevel@tonic-gate work[0] = '\0';
62*0Sstevel@tonic-gate wuser[0] = '\0';
63*0Sstevel@tonic-gate fclose(tmpf);
64*0Sstevel@tonic-gate if (!replying) {
65*0Sstevel@tonic-gate dflag = 1;
66*0Sstevel@tonic-gate Dout(pn, 0, "dflag = 1\n");
67*0Sstevel@tonic-gate if ((debug > 0) && (keepdbgfile == 0)) {
68*0Sstevel@tonic-gate keepdbgfile++;
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate if (ckdlivopts(H_TCOPY, (int *)0) & IGNORE) {
71*0Sstevel@tonic-gate goto skipsend;
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate }
74*0Sstevel@tonic-gate tmpf = doopen(lettmp, "r+", E_TMP);
75*0Sstevel@tonic-gate if (replying) {
76*0Sstevel@tonic-gate fseek(tmpf, let[letnum].adr, 0);
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate for (fgets(line, LSIZE, tmpf);
79*0Sstevel@tonic-gate strncmp(line, header[H_FROM].tag, strlen(header[H_FROM].tag))
80*0Sstevel@tonic-gate == SAME ||
81*0Sstevel@tonic-gate strncmp(line, header[H_FROM1].tag,
82*0Sstevel@tonic-gate strlen(header[H_FROM1].tag)) == SAME; ) {
83*0Sstevel@tonic-gate if ((i = substr(line, "remote from")) != -1) {
84*0Sstevel@tonic-gate for (i = 0, cp = strrchr(line, ' ') + 1;
85*0Sstevel@tonic-gate *cp != '\n';
86*0Sstevel@tonic-gate cp++) {
87*0Sstevel@tonic-gate buf[i++] = *cp;
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate buf[i++] = '!';
90*0Sstevel@tonic-gate buf[i] = '\0';
91*0Sstevel@tonic-gate strcat(work, buf);
92*0Sstevel@tonic-gate if (line[0] == '>') {
93*0Sstevel@tonic-gate i = 6;
94*0Sstevel@tonic-gate } else {
95*0Sstevel@tonic-gate i = 5;
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate for (w = i; line[w] != ' '; w++) {
98*0Sstevel@tonic-gate wuser[w-i] = line[w];
99*0Sstevel@tonic-gate }
100*0Sstevel@tonic-gate wuser[w-i] = '\0';
101*0Sstevel@tonic-gate } else if ((i = substr(line, "forwarded by")) == -1) {
102*0Sstevel@tonic-gate if (line[0] == '>') {
103*0Sstevel@tonic-gate break;
104*0Sstevel@tonic-gate } else {
105*0Sstevel@tonic-gate i = 5;
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate for (w = i; line[w] != ' '; w++) {
108*0Sstevel@tonic-gate wuser[w-i] = line[w];
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate wuser[w-i] = '\0';
111*0Sstevel@tonic-gate } else if ((i = substr(line, "forwarded by")) > -1) {
112*0Sstevel@tonic-gate break;
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate fgets(line, LSIZE, tmpf);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate strcat(work, wuser);
117*0Sstevel@tonic-gate fclose(tmpf);
118*0Sstevel@tonic-gate tmpf = doopen(lettmp, "r+", E_TMP);
119*0Sstevel@tonic-gate if (work[0] != '\0') {
120*0Sstevel@tonic-gate reciplist list;
121*0Sstevel@tonic-gate if (replying) {
122*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf),
123*0Sstevel@tonic-gate "mail %s %s", m_sendto, work);
124*0Sstevel@tonic-gate printf("%s\n", buf);
125*0Sstevel@tonic-gate systm(buf);
126*0Sstevel@tonic-gate return;
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate if (interactive) {
129*0Sstevel@tonic-gate (void) strlcpy(work, my_name, sizeof (work));
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate fprintf(stderr, "%s: Return to %s\n", program, work);
132*0Sstevel@tonic-gate /* Put header info from message aside so it won't */
133*0Sstevel@tonic-gate /* get confused with the Delivery Notification info */
134*0Sstevel@tonic-gate Daffbytecnt = affbytecnt; affbytecnt = 0;
135*0Sstevel@tonic-gate Daffcnt = affcnt; affcnt = 0;
136*0Sstevel@tonic-gate Drcvbytecnt = rcvbytecnt; rcvbytecnt = 0;
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate hdrlines[H_DAFWDFROM].head = hdrlines[H_AFWDFROM].head;
139*0Sstevel@tonic-gate hdrlines[H_DAFWDFROM].tail = hdrlines[H_AFWDFROM].tail;
140*0Sstevel@tonic-gate hdrlines[H_AFWDFROM].head = (struct hdrs *)NULL;
141*0Sstevel@tonic-gate hdrlines[H_AFWDFROM].tail = (struct hdrs *)NULL;
142*0Sstevel@tonic-gate hdrlines[H_DRECEIVED].head = hdrlines[H_RECEIVED].head;
143*0Sstevel@tonic-gate hdrlines[H_DRECEIVED].tail = hdrlines[H_RECEIVED].tail;
144*0Sstevel@tonic-gate hdrlines[H_RECEIVED].head = (struct hdrs *)NULL;
145*0Sstevel@tonic-gate hdrlines[H_RECEIVED].tail = (struct hdrs *)NULL;
146*0Sstevel@tonic-gate hdrlines[H_DTCOPY].head = hdrlines[H_TCOPY].head;
147*0Sstevel@tonic-gate hdrlines[H_DTCOPY].tail = hdrlines[H_TCOPY].tail;
148*0Sstevel@tonic-gate hdrlines[H_TCOPY].head = (struct hdrs *)NULL;
149*0Sstevel@tonic-gate hdrlines[H_TCOPY].tail = (struct hdrs *)NULL;
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate pushlist(H_TCOPY, HEAD, work, FALSE);
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate new_reciplist(&list);
154*0Sstevel@tonic-gate add_recip(&list, work, FALSE);
155*0Sstevel@tonic-gate sendlist(&list, 0, 0);
156*0Sstevel@tonic-gate del_reciplist(&list);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate skipsend:
161*0Sstevel@tonic-gate if (dflag == 9) {
162*0Sstevel@tonic-gate fprintf(stderr,
163*0Sstevel@tonic-gate "%s: Cannot return mail.\n",
164*0Sstevel@tonic-gate program);
165*0Sstevel@tonic-gate mkdead();
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate else if (dflag < 2) {
169*0Sstevel@tonic-gate if (!maxerr && (dflag != 1)) {
170*0Sstevel@tonic-gate maxerr = error;
171*0Sstevel@tonic-gate Dout(pn, 0, "maxerr = %d\n", maxerr);
172*0Sstevel@tonic-gate }
173*0Sstevel@tonic-gate dflag = 0;
174*0Sstevel@tonic-gate error = 0;
175*0Sstevel@tonic-gate Dout(pn, 0, "before return, dflag = %d, error = %d\n",
176*0Sstevel@tonic-gate dflag, error);
177*0Sstevel@tonic-gate }
178*0Sstevel@tonic-gate }
179