]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/cmds/send.c
2 static char sccsid
[] = "@(#)send.c 4.6 7/7/83";
10 #include <sys/types.h>
11 #include <sys/timeb.h>
16 #define SENDMAIL "/usr/lib/sendmail"
17 #define FCCS 10 /* Max number of fcc's allowed */
19 struct swit switches
[] = {
23 "noformat", 0, /* 3 */
27 "noverbose", 0, /* 7 */
34 int verbose
, format
, msgid
, debug
, myuid
;
36 char *anoyes
[]; /* Std no/yes gans array */
39 char tmpfil
[32], fccfold
[FCCS
][128];
46 register char *drft
, *cp
, *addrs
;
51 char *arguments
[50], **argp
;
52 char buf
[BUFSIZ
], name
[NAMESZ
];
53 int state
, compnum
, fd
;
61 cp
= r1bindex(argv
[0], '/');
62 if ((cp
= m_find(cp
)) != NULL
) {
63 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
64 ap
= copyip(ap
, arguments
);
72 switch(smatch(++cp
, switches
)) {
73 case -2:ambigsw(cp
, switches
); /* ambiguous */
76 case -1:fprintf(stderr
, "send: -%s unknown\n", cp
);
78 case 0: verbose
++; debug
++; continue; /* -debug */
79 case 1: drft
= m_maildir(draft
); /* -draft */
81 case 2: fprintf(stderr
, "Send: -format not yet.\n");
83 case 3: format
= 0; continue; /* -noformat */
84 case 4: msgid
= 1; continue; /* -msgid */
85 case 5: msgid
= 0; continue; /* -nomsgid */
86 case 6: verbose
= 1; continue; /* -verbose */
87 case 7: verbose
= 0; continue; /* -noverbose */
88 case 8: help("send [file] [switches]", switches
);
90 case 9: waitfor
= 1; continue; /* -wait */
91 case 10:waitfor
= 0; continue; /* -nowait */
94 fprintf(stderr
, "send: Only 1 message at a time!\n");
100 drft
= m_maildir(draft
);
101 if(stat(drft
, &stbuf
) == -1) {
103 "Draft file: %s doesn't exist.\n", drft
);
106 cp
= concat("Use \"", drft
, "\"? ", 0);
107 if(!gans(cp
, anoyes
))
110 if(stat(drft
, &stbuf
) == -1) {
112 "Draft file: %s doesn't exist.\n", drft
);
119 if((in
= fopen(drft
, "r")) == NULL
) {
120 fprintf(stderr
, "Send: Can't open ");
124 copy(makename("locs", ".tmp"), copy("/tmp/", tmpfil
));
126 if((out
= fopen(tmpfil
, "w")) == NULL
) {
127 fprintf(stderr
, "Can't create %s\n", tmpfil
);
135 putdate(0, out
); /* Tack on the date */
136 /* putfrom(out);*/ /* let sendmail do this */
137 putmsgid(out
); /* and message id if desired */
142 for(compnum
= 1, state
= FLD
;;) {
143 state
= m_getfld(state
, name
, buf
, sizeof buf
, in
);
151 while(*cp
== ' ' || *cp
== '\t')
153 fprintf(out
, "%s: %s", name
, cp
);
154 if(uleq(name
, "fcc")) {
156 fprintf(stderr
, "Send: too many fcc's.\n");
159 copy(cp
, fccfold
[fccind
]);
160 if(cp
= rindex(fccfold
[fccind
], '\n'))
164 while(state
== FLDPLUS
|| state
== FLDEOF
) {
165 state
= m_getfld(state
, name
, buf
, sizeof buf
, in
);
174 fprintf(out
, "\n%s", buf
);
175 while(state
== BODY
) {
176 state
=m_getfld(state
,name
,buf
,sizeof buf
,in
);
185 fprintf(stderr
, "??Message Format Error ");
186 fprintf(stderr
, "in Component #%d.\n", compnum
);
190 fprintf(stderr
, "Getfld returned %d\n", state
);
201 signal(SIGINT
, SIG_IGN
);
202 signal(SIGQUIT
, SIG_IGN
);
203 if(!debug
) { /* Send the mail */
204 fd
= open(tmpfil
, 0);
208 for(state
= 0; state
< fccind
; state
++)
209 fcc(tmpfil
, fccfold
[state
]);
225 *stashp
++ = "sendmail";
232 while ((pid
= fork()) == -1)
238 execv(SENDMAIL
, stashname
);
249 register struct passwd
*pw
;
251 pw
= getpwuid(myuid
);
254 fprintf(stderr
, "Send: WHO ARE YOU?\n");
257 fprintf(out
, "From: %s\n", pw
->pw_name
);
264 auto int i
= sizeof hostname
;
270 gethostname(hostname
, &i
);
272 "Message-Id: <%u.%u.%ld@%s>\n", getpid(), myuid
, now
, hostname
);
283 printf("Fcc: %s...", folder
);
286 while ((child
= fork()) == -1)
291 strcat(fold
, folder
);
292 execl(fileproc
, "file", "-link", "-file", file
, fold
, 0);
295 while((pid
= wait(&status
)) != -1 && pid
!= child
);
297 fprintf(stderr
, "Send: Error on fcc to %s\n", folder
);
309 if(cp
= rindex(file
, '/'))
310 sprintf(buf
, "%.*s", (++cp
)-file
, file
);
320 if(link(file
, buf
) < 0 || unlink(file
) < 0) {
321 fprintf(stderr
, "Send: Backup rename failure ");