$NetBSD: patch-ai,v 1.5 2025/10/12 00:57:39 mrg Exp $ - clean up junk decls that exist in headers, and include the right headers - use fgets instead of gets - fix printf to always have format - when executing a child metamail, propagate the parents options as much as possible - use termios instead of termio/sgtty - give many things return types and (basic) prototypes for GCC 14. --- metamail/metamail.c.orig 1994-02-16 17:57:19.000000000 -0800 +++ metamail/metamail.c 2025-10-11 16:45:09.001504426 -0700 @@ -26,6 +26,8 @@ WITHOUT ANY EXPRESS OR IMPLIED WARRANTIE #include #include +#include "metamail.h" + #ifdef BORLAND #define F_OK 0 extern unsigned _stklen = 16384; @@ -46,12 +48,8 @@ extern char *mktemp(char *); #include #ifndef AMIGA -#ifdef SYSV -#include +#include #include -#else /* SYSV */ -#include -#endif /* SYSV */ #endif /* AMIGA */ #endif /* MICROSOFT */ #endif /* BORLAND */ @@ -83,7 +81,7 @@ extern char *MkRmScript(); #define MAX_FILE_NAME_SIZE 256 #define WRITE_BINARY "w" #else /* AMIGA */ -extern char **environ, *gets(); +extern char **environ; #define CATCOMMAND "cat" #define CATTEMPLATE "cat %s" #define METAMAIL "metamail" @@ -100,15 +98,49 @@ extern char **environ, *gets(); #define CMDSIZE 1200 /* Maximum size of command to execute */ #define LINE_BUF_SIZE 2000 -#ifndef MICROSOFT -extern char *malloc(); -extern char *realloc(); -#endif -extern char *getenv(); -extern char *index(); -extern char *rindex(); +#include +#include + char fileToDelete[MAX_FILE_NAME_SIZE]; +void PauseForUser(void); +void maybephead(char *); +int ProcessArguments(int, char **); +int ExitWithError(char *); +void RestoreTtyState(); +int HandleMessage(char *, int); +int Read822Prefix(int, int); +int ProcessMailcapFiles(char *); +int SaveSquirrelFile(char *); +void PrepareMessage(); +void MkTmpFileName(char *); +int TryBuiltIns(char *); +void TranslateInputToOutput(); +void usage(); +void StripTrailingSpace(char *); +void RunInNewWindow(); +void CreateNewWindowPrefix(); +void SetUpEnvironment(); +int ProcessMailcapFile(); +int TryMailcapEntry(); +int IsDirectory(); +int CtypeMatch(); +int GetMailcapEntry(); +int ExecuteMailcapEntry(); +int OKToRun(); +int ExecuteCommand(); +int PassesTest(); +void BuildCommand(); +int StartRawStdin(); +void strcatquoting(); +int NeedToBeQuiet(); +int NeedToAskBeforeExecuting(); +void SaveTtyState(); +int WriteTmpFile(); +void EliminateNastyChars(); +void strcpynoquotes(); +void phead(); + char *FindParam(); extern FILE *popen(); static char *nomem = "Out of memory!"; @@ -151,6 +183,32 @@ int MightAskBeforeExecuting = 1, JustWriteFiles = 0, ProcessingErrors = 0; +static const char * +makeoptions(void) +{ + static char buf[1024]; + buf[0] = 0; + if (!MightAskBeforeExecuting) + strlcat(buf, " -d", sizeof(buf)); + if (DefinitelyNotTty && MustNotBeTty) + strlcat(buf, " -x", sizeof(buf)); + if (MaybePageOutput) + strlcat(buf, MustPageOutput ? " -P" : " -p", sizeof(buf)); + if (EatLeadingNewlines) + strlcat(buf, " -e", sizeof(buf)); + if (!PrintSomeHeaders && Quiet) + strlcat(buf, " -q", sizeof(buf)); + if (DoInBackground) + strlcat(buf, " -B", sizeof(buf)); + if (!Is822Format) + strlcat(buf, " -b", sizeof(buf)); + if (PrintingMode) + strlcat(buf, " -h", sizeof(buf)); + if (JustWriteFiles) + strlcat(buf, " -w", sizeof(buf)); + return buf; +} + char *ContentType = NULL, *ContentEncoding = NULL, *MailerName = "unknown", @@ -295,6 +353,7 @@ char *auxpath; } } +void main(argc, argv) int argc; char **argv; @@ -387,6 +446,7 @@ char *fname; } } +int HandleMessage(SquirrelFile, nestingdepth) char *SquirrelFile; /* SquirrelFile, if non-NULL, is a place to save a recognized body instead of executing it. */ @@ -497,8 +557,9 @@ int nestingdepth; if (IsAlternative) { if (WroteSquirrelFile) { int retcode; - char Cmd[TMPFILE_NAME_SIZE + 15]; - sprintf(Cmd, "%s %s", METAMAIL, NewSquirrelFile); + char Cmd[TMPFILE_NAME_SIZE + 15 + 1024]; + snprintf(Cmd, sizeof(Cmd), "%s %s %s", METAMAIL, makeoptions(), + NewSquirrelFile); fflush(stdout); fflush(stderr); retcode = system(Cmd); #ifdef MSDOS @@ -579,7 +640,7 @@ int nestingdepth; int overwriteans = -1; do { printf("File %s exists. Do you want to overwrite it (y/n) ?\n", Fname); - s = gets(AnsBuf); + s = fgets(AnsBuf, sizeof(AnsBuf), stdin); if (!s) { overwriteans = 0; } else { @@ -661,6 +722,7 @@ int nestingdepth; return(-1); /* Unrecognized, really */ } +int ProcessArguments(argc, argv) int argc; char **argv; @@ -940,11 +1002,13 @@ char **argv; return(0); } +void usage() { fprintf(stderr, "Usage: metamail [-b] [-B] [-d] [-e] [-h] [-r] [-R] [-p] [-P] [-x] [-y] [-z] [-c content-type] [-E content-transfer-encoding] [-f from-name] [-m mailername] [-s subject] [message-file-name]\n"); ExitWithError(NULL); } +void RunInNewWindow(argv, argc, SourceFileNamePtr) char **argv, **SourceFileNamePtr; int argc; @@ -1026,6 +1090,7 @@ struct MailcapEntry BuiltInsAlternative[ {"text/plain", CATTEMPLATE, NULL, 0, 1, 0, "plain text", LPRTEMPLATE}, {NULL, NULL, NULL, 0, 0, 0}}; +int ProcessMailcapFiles(SquirrelFile) char *SquirrelFile; { @@ -1082,6 +1147,7 @@ char *SquirrelFile; #endif /* MICROSOFT */ } +int TryBuiltIns(SquirrelFile) char *SquirrelFile; { @@ -1094,6 +1160,7 @@ char *SquirrelFile; return(-1); } +int ProcessMailcapFile(file, SquirrelFile) char *file, *SquirrelFile; { @@ -1166,6 +1233,7 @@ eatmore: } } +int TryMailcapEntry(mc, SquirrelFile) struct MailcapEntry mc; char *SquirrelFile; @@ -1189,6 +1257,7 @@ char *SquirrelFile; return(-1); } +int SaveSquirrelFile(SquirrelFile) char *SquirrelFile; { @@ -1202,9 +1271,9 @@ char *SquirrelFile; fprintf(outfp, "Content-type: %s", ContentType); for (j=0; j