#include <errno.h>
#include <setjmp.h>
#include <signal.h>
-#include <h/mts.h>
#include <h/tws.h>
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/utils.h>
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
-
extern int debugsw;
extern int endian; /* mhmisc.c */
};
-/* ftpsbr.c */
-int ftp_get(char *, char *, char *, char *, char *, char *, int, int);
-
/* mhcachesbr.c */
int find_cache(CT, int, int *, char *, char *, int);
/*
** Check if file is actually standard input
*/
- if ((is_stdin = !(strcmp(file, "-")))) {
+ if ((is_stdin = (strcmp(file, "-")==0))) {
char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
if (tfile == NULL) {
advise("mhparse", "unable to create temporary file");
if (buffer[0] != '-' || buffer[1] != '-')
continue;
if (inout) {
- if (strcmp(buffer + 2, m->mp_start))
+ if (strcmp(buffer + 2, m->mp_start)!=0)
continue;
next_part:
if ((part = (struct part *) calloc(1, sizeof(*part)))
openBase64(CT ct, char **file)
{
int bitno, cc, digested;
- int fd, len, skip;
+ int fd, len, skip, own_ct_fp = 0;
unsigned long bits;
unsigned char value, *b, *b1, *b2, *b3;
unsigned char *cp, *ep;
if ((len = ct->c_end - ct->c_begin) < 0)
adios(NULL, "internal error(1)");
- if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
- content_error(ct->c_file, ct, "unable to open for reading");
- return NOTOK;
+ if (!ct->c_fp) {
+ if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
+ content_error(ct->c_file, ct,
+ "unable to open for reading");
+ return NOTOK;
+ }
+ own_ct_fp = 1;
}
if ((digested = ct->c_digested))
ready_to_go:
*file = ce->ce_file;
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return fileno(ce->ce_fp);
clean_up:
free_encoding(ct, 0);
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return NOTOK;
}
static int
openQuoted(CT ct, char **file)
{
- int cc, digested, len, quoted;
+ int cc, digested, len, quoted, own_ct_fp = 0;
unsigned char *cp, *ep;
char buffer[BUFSIZ];
unsigned char mask;
return NOTOK;
}
- if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
- content_error(ce->ce_file, ct,
- "unable to fopen for reading/writing");
- return NOTOK;
- }
-
if ((len = ct->c_end - ct->c_begin) < 0)
adios(NULL, "internal error(2)");
- if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
- content_error(ct->c_file, ct, "unable to open for reading");
- return NOTOK;
+ if (!ct->c_fp) {
+ if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
+ content_error(ct->c_file, ct,
+ "unable to open for reading");
+ return NOTOK;
+ }
+ own_ct_fp = 1;
}
if ((digested = ct->c_digested))
ready_to_go:
*file = ce->ce_file;
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return fileno(ce->ce_fp);
clean_up:
free_encoding(ct, 0);
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return NOTOK;
}
int
open7Bit(CT ct, char **file)
{
- int cc, fd, len;
+ int cc, fd, len, own_ct_fp = 0;
char buffer[BUFSIZ];
/* sbeck -- handle suffixes */
char *cp;
if ((len = ct->c_end - ct->c_begin) < 0)
adios(NULL, "internal error(3)");
- if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
- content_error(ct->c_file, ct, "unable to open for reading");
- return NOTOK;
+ if (!ct->c_fp) {
+ if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
+ content_error(ct->c_file, ct,
+ "unable to open for reading");
+ return NOTOK;
+ }
+ own_ct_fp = 1;
}
lseek(fd = fileno(ct->c_fp), (off_t) ct->c_begin, SEEK_SET);
ready_to_go:
*file = ce->ce_file;
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return fileno(ce->ce_fp);
clean_up:
free_encoding(ct, 0);
+ if (own_ct_fp) {
+ fclose(ct->c_fp);
+ ct->c_fp = NULL;
+ }
return NOTOK;
}
CE ce;
static char *username = NULL;
static char *password = NULL;
+ int child_id, vecp;
+ char *vec[9];
e = ct->c_ctexbody;
ce = ct->c_cefile;
if ((ftp = context_find(nmhaccessftp)) && !*ftp)
ftp = NULL;
-#ifndef BUILTIN_FTP
if (!ftp)
return NOTOK;
-#endif
switch (openExternal(e->eb_parent, e->eb_content, ce, file, &fd)) {
case NOTOK:
return NOTOK;
}
-#ifdef BUILTIN_FTP
- if (ftp)
-#endif
- {
- int child_id, i, vecp;
- char *vec[9];
-
- vecp = 0;
- vec[vecp++] = mhbasename(ftp);
- vec[vecp++] = e->eb_site;
- vec[vecp++] = user;
- vec[vecp++] = pass;
- vec[vecp++] = e->eb_dir;
- vec[vecp++] = e->eb_name;
- vec[vecp++] = ce->ce_file,
- vec[vecp++] = e->eb_mode &&
- !mh_strcasecmp(e->eb_mode, "ascii") ?
- "ascii" : "binary";
- vec[vecp] = NULL;
-
- fflush(stdout);
-
- for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
- sleep(5);
- switch (child_id) {
- case NOTOK:
- adios("fork", "unable to");
- /* NOTREACHED */
+ vecp = 0;
+ vec[vecp++] = mhbasename(ftp);
+ vec[vecp++] = e->eb_site;
+ vec[vecp++] = user;
+ vec[vecp++] = pass;
+ vec[vecp++] = e->eb_dir;
+ vec[vecp++] = e->eb_name;
+ vec[vecp++] = ce->ce_file,
+ vec[vecp++] = e->eb_mode &&
+ !mh_strcasecmp(e->eb_mode, "ascii") ?
+ "ascii" : "binary";
+ vec[vecp] = NULL;
- case OK:
- close(fileno(ce->ce_fp));
- execvp(ftp, vec);
- fprintf(stderr, "unable to exec ");
- perror(ftp);
- _exit(-1);
- /* NOTREACHED */
+ fflush(stdout);
- default:
- if (pidXwait(child_id, NULL)) {
-#ifdef BUILTIN_FTP
-losing_ftp:
-#endif
- username = password = NULL;
- ce->ce_unlink = 1;
- return NOTOK;
- }
- break;
+ switch (child_id = fork()) {
+ case NOTOK:
+ adios("fork", "unable to");
+ /* NOTREACHED */
+
+ case OK:
+ close(fileno(ce->ce_fp));
+ execvp(ftp, vec);
+ fprintf(stderr, "unable to exec ");
+ perror(ftp);
+ _exit(-1);
+ /* NOTREACHED */
+
+ default:
+ if (pidXwait(child_id, NULL)) {
+ username = password = NULL;
+ ce->ce_unlink = 1;
+ return NOTOK;
}
+ break;
}
-#ifdef BUILTIN_FTP
- else if (ftp_get(e->eb_site, user, pass, e->eb_dir, e->eb_name,
- ce->ce_file, e->eb_mode && !mh_strcasecmp(e->eb_mode,
- "ascii"), 0) == NOTOK)
- goto losing_ftp;
-#endif
if (cachefile[0]) {
if (caching)
static int
openMail(CT ct, char **file)
{
- int child_id, fd, i, vecp;
+ int child_id, fd, vecp;
int len, buflen;
char *bp, buffer[BUFSIZ], *vec[7];
struct exbody *e = ct->c_ctexbody;
return NOTOK;
vecp = 0;
- vec[vecp++] = mhbasename(mailproc);
+ vec[vecp++] = "mhmail";
vec[vecp++] = e->eb_server;
vec[vecp++] = "-subject";
vec[vecp++] = e->eb_subject ? e->eb_subject : "mail-server request";
vec[vecp++] = e->eb_body;
vec[vecp] = NULL;
- for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
- sleep(5);
- switch (child_id) {
+ switch (child_id = fork()) {
case NOTOK:
advise("fork", "unable to");
return NOTOK;
case OK:
- execvp(mailproc, vec);
+ execvp(*vec, vec);
fprintf(stderr, "unable to exec ");
- perror(mailproc);
+ perror(*vec);
_exit(-1);
/* NOTREACHED */