*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
+#include "h/mh.h"
+#include "sbr/context_find.h"
+#include "sbr/readconfig.h"
+#include "sbr/ambigsw.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
X("norfc934mode", 0, NRFC934SW) \
X("verbose", 0, VERBSW) \
X("noverbose", 0, NVERBSW) \
X("norfc934mode", 0, NRFC934SW) \
X("verbose", 0, VERBSW) \
X("noverbose", 0, NVERBSW) \
X("rcache policy", 0, RCACHESW) \
X("wcache policy", 0, WCACHESW) \
X("contentid", 0, CONTENTIDSW) \
X("nocontentid", 0, NCONTENTIDSW) \
X("headerencoding encoding-algorithm", 0, HEADERENCSW) \
X("autoheaderencoding", 0, AUTOHEADERENCSW) \
X("rcache policy", 0, RCACHESW) \
X("wcache policy", 0, WCACHESW) \
X("contentid", 0, CONTENTIDSW) \
X("nocontentid", 0, NCONTENTIDSW) \
X("headerencoding encoding-algorithm", 0, HEADERENCSW) \
X("autoheaderencoding", 0, AUTOHEADERENCSW) \
X("version", 0, VERSIONSW) \
X("help", 0, HELPSW) \
X("debug", -5, DEBUGSW) \
X("version", 0, VERSIONSW) \
X("help", 0, HELPSW) \
X("debug", -5, DEBUGSW) \
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(MHBUILD);
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(MHBUILD);
#define MIMEENCODING_SWITCHES \
X("base64", 0, BASE64SW) \
X("quoted-printable", 0, QUOTEDPRINTSW) \
#define MIMEENCODING_SWITCHES \
X("base64", 0, BASE64SW) \
X("quoted-printable", 0, QUOTEDPRINTSW) \
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(MIMEENCODING);
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(MIMEENCODING);
-static int unlink_outfile = 0;
-
-static void unlink_done (int) NORETURN;
-
-/* mhbuildsbr.c */
-int output_message (CT, char *);
-int output_message_fp (CT, FILE *, char*);
-
-/* mhlistsbr.c */
-int list_all_messages (CT *, int, int, int, int);
- int sizesw = 1, headsw = 1, directives = 1, autobuild = 0;
+ bool sizesw = true;
+ bool headsw = true;
+ bool directives = true;
+ bool autobuild = false;
+ bool dist = false;
+ bool verbosw = false;
+ bool dispo = false;
+ size_t maxunencoded = MAXTEXTPERLN;
- done=unlink_done;
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
+ if (nmh_init(argv[0], true, false)) { return 1; }
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
- adios (NULL, "cannot specify both standard input and a file");
- else
- compfile = cp;
- listsw = 0; /* turn off -list if using standard in/out */
- verbosw = 0; /* turn off -verbose listings */
+ die("cannot specify both standard input and a file");
+ compfile = cp;
+ listsw = false; /* turn off -list if using standard in/out */
+ verbosw = false; /* turn off -verbose listings */
case HELPSW:
snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
case HELPSW:
snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
- adios (NULL, "missing argument to %s", argp[-2]);
- switch (*icachesw = smatch (cp, caches)) {
+ die("missing argument to %s", argp[-2]);
+ switch (*icachesw = smatch (cp, cache_policy)) {
switch (encoding = smatch (cp, encodingswitches)) {
case AMBIGSW:
ambigsw (cp, encodingswitches);
done (1);
case UNKWNSW:
switch (encoding = smatch (cp, encodingswitches)) {
case AMBIGSW:
ambigsw (cp, encodingswitches);
done (1);
case UNKWNSW:
+ case MAXUNENCSW:
+ if (!(cp = *argp++) || *cp == '-')
+ die("missing argument to %s", argp[-2]);
+ if ((maxunencoded = atoi(cp)) < 1)
+ die("Invalid argument for %s: %s", argp[-2], cp);
+ if (maxunencoded > 998)
+ die("limit of -maxunencoded is 998");
+ continue;
+
*/
if ((cp = getenv ("MHBUILD"))) {
if ((fp = fopen (cp, "r"))) {
*/
if ((cp = getenv ("MHBUILD"))) {
if ((fp = fopen (cp, "r"))) {
- readconfig ((struct node **) 0, fp, cp, 0);
+ readconfig(NULL, fp, cp, 0);
* Read the standard profile setup
*/
if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
* Read the standard profile setup
*/
if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) {
- readconfig ((struct node **) 0, fp, cp, 0);
+ readconfig(NULL, fp, cp, 0);
/* Check for private cache location */
if (!(cache_private = context_find (nmhprivcache)))
cache_private = ".cache";
/* Check for private cache location */
if (!(cache_private = context_find (nmhprivcache)))
cache_private = ".cache";
if (!context_find ("path"))
free (path ("./", TFOLDER));
/* Check if we have a file to process */
if (!compfile)
if (!context_find ("path"))
free (path ("./", TFOLDER));
/* Check if we have a file to process */
if (!compfile)
/*
* Process the composition file from standard input.
*/
if (compfile[0] == '-' && compfile[1] == '\0') {
if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
/*
* Process the composition file from standard input.
*/
if (compfile[0] == '-' && compfile[1] == '\0') {
if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
- strncpy (infile, cp, sizeof(infile));
- while (fgets (buffer, BUFSIZ, stdin))
- fputs (buffer, fp);
+ while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
+ if (fwrite(buffer, 1, n, fp) != n) {
+ die("error copying to temporary file");
+ }
+ }
- ct = build_mime (infile, autobuild, directives, header_encoding);
+ ct = build_mime (infile, autobuild, dist, directives, header_encoding,
+ maxunencoded, verbosw);
- adios(NULL, "Unable to open %s for reading", infile);
+ die("Unable to open %s for reading", infile);
+ }
+ while ((n = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
+ if (fwrite(buffer, 1, n, stdout) != n) {
+ die("error copying %s to stdout", infile);
+ }
- ct = build_mime (compfile, autobuild, directives, header_encoding);
+ ct = build_mime (compfile, autobuild, dist, directives, header_encoding,
+ maxunencoded, verbosw);
/* output MIME message to this temporary file */
if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
/* output MIME message to this temporary file */
if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
- list_all_messages (cts, headsw, sizesw, verbosw, debugsw);
+ list_all_messages (cts, headsw, sizesw, verbosw, debugsw, dispo);
/* Rename composition draft */
snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
/* Rename composition draft */
snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));