]> diplodocus.org Git - nmh/commitdiff
Merge branch 'tmpfiles'
authorDavid Levine <levinedl@acm.org>
Sun, 26 Jan 2014 17:23:53 +0000 (11:23 -0600)
committerDavid Levine <levinedl@acm.org>
Sun, 26 Jan 2014 17:23:53 +0000 (11:23 -0600)
120 files changed:
Makefile.am
configure.ac
docs/README-ATTACHMENTS
docs/README.developers
docs/contrib/build_nmh
docs/contrib/ml
docs/pending-release-notes
h/mh.h
h/mhparse.h
h/prototypes.h
man/forw.man
man/mh-profile.man
man/mhbuild.man
man/mhpath.man
man/mhshow.man
man/repl.man
man/scan.man
man/send.man
man/show.man
man/whatnow.man
sbr/check_charset.c
sbr/context_save.c
sbr/fmt_compile.c
sbr/fmt_scan.c
sbr/folder_delmsgs.c
sbr/gans.c
sbr/lock_file.c
sbr/m_atoi.c
sbr/m_backup.c
sbr/m_convert.c
sbr/m_mktemp.c
sbr/mime_type.c [new file with mode: 0644]
sbr/push.c
sbr/seq_save.c
sbr/signals.c
sbr/uprf.c
sbr/utils.c
sbr/vector.c
test/common.sh.in
test/dist/test-dist
test/mhbuild/test-attach
test/mhbuild/test-utf8-body
test/mhmail/test-mhmail
test/pick/test-pick
test/post/test-messageid
test/post/test-mts
test/post/test-post-aliases
test/post/test-post-basic
test/post/test-post-bcc
test/post/test-post-dcc
test/post/test-post-envelope
test/post/test-post-fcc
test/post/test-post-group
test/post/test-post-multiple
test/scan/test-scan-multibyte
test/whatnow/test-attach-detach
uip/ali.c
uip/anno.c
uip/annosbr.c
uip/ap.c
uip/attach.c [deleted file]
uip/burst.c
uip/comp.c
uip/conflict.c
uip/dist.c
uip/distsbr.c
uip/dp.c
uip/dropsbr.c
uip/flist.c
uip/fmtdump.c
uip/fmttest.c
uip/folder.c
uip/forw.c
uip/forwsbr.c
uip/inc.c
uip/install-mh.c
uip/mark.c
uip/mhbuild.c
uip/mhbuildsbr.c
uip/mhcachesbr.c
uip/mhfixmsg.c
uip/mhfree.c
uip/mhl.c
uip/mhlist.c
uip/mhlsbr.c
uip/mhmail
uip/mhn.c
uip/mhparam.c
uip/mhparse.c
uip/mhpath.c
uip/mhshow.c
uip/mhstore.c
uip/mhstoresbr.c
uip/mhtest.c
uip/msgchk.c
uip/msh.c
uip/mshcmds.c
uip/new.c
uip/packf.c
uip/pick.c
uip/post.c
uip/prompter.c
uip/rcvdist.c
uip/rcvpack.c
uip/rcvstore.c
uip/rcvtty.c
uip/refile.c
uip/repl.c
uip/rmf.c
uip/rmm.c
uip/scan.c
uip/send.c
uip/sendsbr.c
uip/show.c
uip/slocal.c
uip/sortm.c
uip/viamail.c
uip/whatnow.c
uip/whatnowsbr.c
uip/whom.c

index 903a45e..626fd82 100644 (file)
@@ -65,6 +65,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \
        test/install-mh/test-install-mh \
        test/locking/test-datalocking test/locking/test-spoollocking \
        test/manpages/test-manpages \
+       test/mhbuild/test-attach \
        test/mhbuild/test-forw test/mhbuild/test-header-encode \
        test/mhbuild/test-utf8-body \
        test/mhfixmsg/test-mhfixmsg \
@@ -266,6 +267,7 @@ EXTRA_DIST = config/version.sh sbr/sigmsg.awk etc/mts.conf.in \
             test/README test/fakesendmail $(TESTS) test/inc/deb359167.mbox \
             test/inc/fromline.txt test/inc/msgheader.txt test/inc/filler.txt \
             test/inc/md5sums test/mhmail/attachment.txt \
+            test/mhbuild/tiny.jpg \
             test/post/test-post-common.sh test/valgrind.supp uip/mhmail \
             SPECS/nmh.spec SPECS/build-nmh-cygwin $(man_SRCS)
 
@@ -288,11 +290,11 @@ uip_burst_SOURCES = uip/burst.c uip/mhparse.c uip/mhmisc.c uip/mhfree.c \
 uip_burst_LDADD = $(LDADD) $(POSTLINK)
 
 uip_comp_SOURCES = uip/comp.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \
-                  uip/attach.c uip/annosbr.c uip/distsbr.c
+                  uip/annosbr.c uip/distsbr.c
 uip_comp_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK)
 
 uip_dist_SOURCES = uip/dist.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \
-                  uip/attach.c uip/annosbr.c uip/distsbr.c uip/forwsbr.c
+                  uip/annosbr.c uip/distsbr.c uip/forwsbr.c
 uip_dist_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK)
 
 uip_flist_SOURCES = uip/flist.c
@@ -302,7 +304,7 @@ uip_folder_SOURCES = uip/folder.c
 uip_folder_LDADD = $(LDADD) $(POSTLINK)
 
 uip_forw_SOURCES = uip/forw.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \
-                  uip/attach.c uip/annosbr.c uip/distsbr.c uip/forwsbr.c
+                  uip/annosbr.c uip/distsbr.c uip/forwsbr.c
 uip_forw_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK)
 
 uip_inc_SOURCES = uip/inc.c uip/scansbr.c uip/dropsbr.c uip/popsbr.c
@@ -316,7 +318,7 @@ uip_mark_LDADD = $(LDADD) $(POSTLINK)
 
 uip_mhbuild_SOURCES = uip/mhbuild.c uip/mhbuildsbr.c uip/mhcachesbr.c \
                      uip/mhlistsbr.c uip/mhoutsbr.c uip/mhmisc.c  \
-                     uip/mhfree.c uip/mhparse.c uip/md5.c uip/attach.c
+                     uip/mhfree.c uip/mhparse.c uip/md5.c
 uip_mhbuild_LDADD = $(LDADD) $(TERMLIB) $(POSTLINK)
 
 uip_mhfixmsg_SOURCES = uip/mhfixmsg.c uip/mhparse.c uip/mhcachesbr.c \
@@ -372,7 +374,7 @@ uip_refile_SOURCES = uip/refile.c
 uip_refile_LDADD = $(LDADD) $(POSTLINK)
 
 uip_repl_SOURCES = uip/repl.c uip/replsbr.c uip/whatnowproc.c uip/whatnowsbr.c \
-                  uip/sendsbr.c uip/attach.c uip/annosbr.c uip/distsbr.c
+                  uip/sendsbr.c uip/annosbr.c uip/distsbr.c
 uip_repl_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK)
 
 uip_rmf_SOURCES = uip/rmf.c
@@ -384,7 +386,7 @@ uip_rmm_LDADD = $(LDADD) $(POSTLINK)
 uip_scan_SOURCES = uip/scan.c uip/scansbr.c
 uip_scan_LDADD = $(LDADD) $(TERMLIB) $(ICONVLIB) $(POSTLINK)
 
-uip_send_SOURCES = uip/send.c uip/sendsbr.c uip/attach.c uip/annosbr.c \
+uip_send_SOURCES = uip/send.c uip/sendsbr.c uip/annosbr.c \
                   uip/distsbr.c
 uip_send_LDADD = $(LDADD) $(POSTLINK)
 
@@ -395,7 +397,7 @@ uip_sortm_SOURCES = uip/sortm.c
 uip_sortm_LDADD = $(LDADD) $(POSTLINK)
 
 uip_whatnow_SOURCES = uip/whatnow.c uip/whatnowsbr.c uip/sendsbr.c \
-                     uip/attach.c uip/annosbr.c uip/distsbr.c
+                     uip/annosbr.c uip/distsbr.c
 uip_whatnow_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(POSTLINK)
 
 uip_whom_SOURCES = uip/whom.c uip/distsbr.c
@@ -447,7 +449,7 @@ uip_slocal_SOURCES = uip/slocal.c uip/aliasbr.c uip/dropsbr.c
 uip_slocal_LDADD = $(LDADD) $(NDBM_LIBS) $(POSTLINK)
 
 uip_viamail_SOURCES = uip/viamail.c uip/mhmisc.c uip/mhoutsbr.c uip/sendsbr.c \
-                     uip/attach.c uip/annosbr.c uip/distsbr.c
+                     uip/annosbr.c uip/distsbr.c
 uip_viamail_LDADD = $(LDADD) $(POSTLINK)
 
 test_getfullname_SOURCES = test/getfullname.c
@@ -567,7 +569,7 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/arglist.c \
                      sbr/m_atoi.c sbr/m_backup.c sbr/m_convert.c \
                      sbr/m_draft.c sbr/m_getfld.c sbr/m_gmprot.c \
                      sbr/m_maildir.c sbr/m_name.c sbr/m_rand.c \
-                     sbr/makedir.c sbr/message_id.c sbr/mts.c \
+                     sbr/makedir.c sbr/message_id.c sbr/mime_type.c sbr/mts.c \
                      sbr/norm_charmap.c sbr/path.c \
                      sbr/peekc.c sbr/pidwait.c sbr/pidstatus.c \
                      sbr/print_help.c sbr/print_sw.c sbr/print_version.c \
index 61a8beb..35118f3 100644 (file)
@@ -28,14 +28,6 @@ dnl Do you want to debug nmh?
 AC_ARG_ENABLE([debug],
   AS_HELP_STRING([--enable-debug],[enable nmh code debugging]))
 
-dnl Do you want to disable use of locale functions
-AH_TEMPLATE([LOCALE],
-[Undefine if you don't want locale features.  By default this is defined.])
-AC_ARG_ENABLE([locale],
-  [AS_HELP_STRING([--disable-locale], [turn off locale features])],
-  [AS_IF([test x$enableval = xyes], [AC_DEFINE(LOCALE)])],
-  [AC_DEFINE(LOCALE)])
-
 dnl Do you want client-side support for using SASL for authentication?
 dnl Note that this code will be enabled for both POP and SMTP
 AC_ARG_WITH([cyrus-sasl], AS_HELP_STRING([--with-cyrus-sasl],
@@ -337,8 +329,7 @@ AS_CASE(["$host_os"],
                 [CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"])])
 
 AC_HEADER_TIOCGWINSZ
-AC_CHECK_HEADERS([fcntl.h langinfo.h wchar.h wctype.h sys/param.h \
-                 sys/time.h sys/stream.h])
+AC_CHECK_HEADERS([fcntl.h wchar.h wctype.h sys/param.h sys/time.h sys/stream.h])
 
 AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
   [Define to 1 if `struct winsize' requires <sys/ptem.h>.]),,
@@ -350,7 +341,7 @@ AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
 dnl ---------------
 dnl CHECK FUNCTIONS
 dnl ---------------
-AC_CHECK_FUNCS([wcwidth mbtowc nl_langinfo getutxent arc4random])
+AC_CHECK_FUNCS([wcwidth mbtowc getutxent arc4random])
 
 dnl Check for multibyte character set support
 AS_IF([test "x$ac_cv_header_wchar_h" = "xyes" -a \
index dc04662..db096d6 100644 (file)
@@ -1,3 +1,10 @@
+This document describes the previous attach interface.  The attach
+interface has changes for nmh 1.6 and later.  The interface is
+documented in send(1), whatnow(1), and mhbuild(1).  No configuration
+is required, and the same commands exist in whatnow; the two main
+differences are that the header is now named "Attach", and mhbuild takes
+care of the actual header processing.
+
 Jon Steinhart's (jon@fourwinds.com) Attachment Handling Mods
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
index 1d3fd73..76f650d 100644 (file)
@@ -22,15 +22,6 @@ commit checklist
 8. notify nmh-users?
 
 
----------------------------------
-C library/system call usage notes
----------------------------------
-* Use m_mktemp2() or m_mktemp() instead of mkstemp(3) (see section on
-  nmh temporary files below).
-* Use m_unlink() instead of unlink(3).
-* Use done() instead of _exit(3) except after a fork(3).
-
-
 -------------------------
 autoconf & automake files
 -------------------------
@@ -171,21 +162,6 @@ OS function  nmh-local version to use instead
 getpass()    nmh_getpass()
 
 
--------------------
-nmh temporary files
--------------------
-
-To create a temporary file, use m_mktemp2() or m_mktemp().  They use
-mkstemp(3), but they also register the temporary file for removal on
-program termination.  So, do not use mkstemp() directly.
-
-To further support this, nmh_init() must be called at the beginning of
-main().  And, if a child process is not going to immediately call one
-of the exec(3) functions or _exit(3) after a fork(3), it should call
-unregister_for_removal(0).  Finally, nmh_init() sets up signal handlers
-for several signals:  these signal handlers should not be disabled.
-
-
 --------------
 nmh test suite
 --------------
index 66383ac..ba421bf 100755 (executable)
@@ -223,7 +223,7 @@ config_opts="--prefix=$config_prefix"
 [ "$config_tls" = y ]  &&  \
   config_opts="$config_opts --with-tls"
 [ $config_debug = y ]  &&  \
-  config_opts="$config_opts --enable-debug"
+  config_opts="$config_opts --enable-debug --enable-assert"
 
 
 #### dotlocking, the usual default, requires chgrp and chmod of inc.
index f5796c4..66bcf10 100755 (executable)
@@ -117,7 +117,7 @@ do_viewhtml()
        > /tmp/ml-mhshow-html$$
 
     MHSHOW=/tmp/ml-mhshow-html$$ \
-    MM_CHARSET=us-ascii \
+    LC_ALL=C \
        mhshow -type text/html "$@"
 
     rm -f /tmp/ml-mhshow-html$$
index cfe66e3..b2d2a82 100644 (file)
@@ -67,6 +67,11 @@ NEW FEATURES
   directive that send(1) will use.
 - mhbuild(1) now supports the -auto/-noauto flags (to be used by send(1)
   when invoking mhbuild automatically).
+- mhbuild(1) now is automatically run by send, to insure that all outgoing
+  messages have proper MIME formatting.
+- A new header, "Attach", is supported by mhbuild; it is used to replace
+  previous functionality (which by default used a header named
+  Nmh-Attachment).
 
 -----------------
 OBSOLETE FEATURES
@@ -109,6 +114,9 @@ OBSOLETE FEATURES
   ap(8) commands has been removed.
 - "make install" no longer strips executables.  Use "make install-strip"
   instead.
+- The environment variable MM_CHARSET to indicate the native character
+  set is no longer supported.  The native character set will be solely
+  determined by the locale settings.
 
 -------------------
 DEPRECATED FEATURES
diff --git a/h/mh.h b/h/mh.h
index 3b36141..999d600 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -122,8 +122,6 @@ struct swit {
 
 extern struct swit anoyes[];   /* standard yes/no switches */
 
-#define ATTACHFORMATS 3                /* Number of send attach formats. */
-
 /*
  * general folder attributes
  */
@@ -174,7 +172,6 @@ svector_t svector_create (size_t);
 void svector_free (svector_t);
 char *svector_push_back (svector_t, char *);
 char *svector_at (svector_t, size_t);
-char **svector_find(svector_t, const char *);
 char **svector_strs (svector_t);
 size_t svector_size (svector_t);
 
@@ -360,8 +357,6 @@ typedef struct m_getfld_state *m_getfld_state_t;
 #define LINK   "@"             /* Name of link to file to which you are */
                                /* replying. */
 
-#define NMH_ATTACH_HEADER "Nmh-Attachment"  /* Default header for -attach */
-
 /*
  * credentials management
  */
index 62e6c0b..29fc1af 100644 (file)
@@ -296,6 +296,9 @@ CT parse_mime (char *);
  *               that the composition file is already in MIME format
  *               and will not be processed further.  Otherwise, an
  *               error is generated.
+ * dist                - A flag to indicate if we are being run by "dist".  In
+ *               that case, add no MIME headers to the message.  Existing
+ *               headers will still be encoded by RFC 2047.
  * directives  - A flag to control whether or not build directives are
  *               processed by default.
  * encoding    - The default encoding to use when doing RFC 2047 header
@@ -306,7 +309,8 @@ CT parse_mime (char *);
  * -auto flag is set and a MIME-Version header is encountered, the return
  * value is NULL.
  */
-CT build_mime (char *infile, int autobuild, int directives, int encoding);
+CT build_mime (char *infile, int autobuild, int dist, int directives,
+              int encoding);
 
 int add_header (CT, char *, char *);
 int get_ctinfo (char *, CT, int);
index eefbfec..a418431 100644 (file)
@@ -191,11 +191,30 @@ int m_putenv (char *, char *);
 int m_rand (unsigned char *, size_t);
 char *m_mktemp(const char *, int *, FILE **);
 char *m_mktemp2(const char *, const char *, int *, FILE **);
-char *get_temp_dir();
 void m_unknown(m_getfld_state_t *, FILE *);
 int makedir (char *);
 char *message_id (time_t, int);
 
+/*
+ * Return a MIME content-type string for the specified file.
+ *
+ * If the system supports it, will use the "file" command to determine
+ * the appropriate content-type.  Otherwise it will try to determine the
+ * content-type from the suffix.  If that fails, the file will be scanned
+ * and either assigned a MIME type of text/plain or application/octet-stream
+ * depending if binary content is present.
+ *
+ * Arguments:
+ *
+ * filename    - The name of the file to determine the MIME type of.
+ *
+ * Returns a pointer to a content-type string (which may include MIME
+ * parameters, such as charset).  Returns a NULL if it cannot determine
+ * the MIME type of the file.  Returns allocated storage that must be
+ * free'd.
+ */
+char *mime_type(const char *filename);
+
 /*
  * Clear the screen, using the appropriate entry from the terminfo database
  */
@@ -337,7 +356,7 @@ int sc_length(void);
 int sc_width(void);
 int build_form (char *, char *, int *, char *, char *, char *, char *,
                char *, char *);
-int sendsbr (char **, int, char *, char *, struct stat *, int, char *, int);
+int sendsbr (char **, int, char *, char *, struct stat *, int);
 int SOprintf (char *, ...);
 int what_now (char *, int, int, char *, char *,
        int, struct msgs *, char *, int, char *, int);
@@ -346,23 +365,8 @@ int writeBase64aux(FILE *, FILE *);
 int writeBase64 (unsigned char *, size_t, unsigned char *);
 int writeBase64raw (unsigned char *, size_t, unsigned char *);
 
-/*
- * prototypes to support whatnow attach
- */
-int   attach(char *, char *, char *, size_t, char *, size_t, int);
-void  clean_up_temporary_files(const char *, const char *);
-char *mime_type(const char *);
-char *construct_build_directive(char *, const char *, int);
-
 /*
  * credentials management
  */
 void init_credentials_file ();
 int nmh_get_credentials (char *, char *, int, nmh_creds_t);
-
-/*
- * temporary file management
- */
-int nmh_init(const char *argv0, int read_context);
-int m_unlink(const char *);
-void unregister_for_removal(int remove_files);
index 2b73408..414f9d7 100644 (file)
@@ -275,18 +275,7 @@ composition file. Note that
 .B nmh
 will not invoke
 .B mhbuild
-automatically, unless you
-add this line to your
-.I \&.mh\(ruprofile
-file:
-.PP
-.RS 5
-.nf
-automimeproc: 1
-.fi
-.RE
-.PP
-Otherwise, you must specifically give the command
+automatically; you must specifically give the command
 .PP
 .RS 5
 .nf
index 9f0190f..14d1c5a 100644 (file)
@@ -156,16 +156,6 @@ EDITOR environment variables.
 (profile, default: vi)
 .RE
 .PP
-.BR automimeproc :
-.RS 5
-If defined and set to 1, then the
-.B whatnow
-program will automatically
-invoke the buildmimeproc (discussed below) to process each message as a MIME
-composition draft before it is sent.
-(profile, no default)
-.RE
-.PP
 .BR Msg\-Protect :
 600
 .RS 5
@@ -783,48 +773,6 @@ additional user profile (file) to be read by
 in addition to the mhn.defaults profile.
 .RE
 .PP
-.B $MM_CHARSET
-.RS 5
-With this environment variable, you can specify
-the native character set you are using.  You must be able to display
-this character set on your terminal.
-.PP
-This variable is checked to see if a RFC 2047 header field should be
-decoded (in
-.BR inc ,
-.BR scan ,
-.BR mhl ).
-This variable is
-checked by
-.B show
-to see if the
-.I showproc
-or
-.I showmimeproc
-should
-be called, since showmimeproc will be called if a text message uses
-a character set that doesn't match
-.BR $MM_CHARSET .
-This variable is
-checked by
-.B mhshow
-for matches against the charset parameter
-of text contents to decide it the text content can be displayed
-without modifications to your terminal.  This variable is checked by
-.B mhbuild
-to decide what character set to specify in the charset
-parameter of text contents containing 8\-bit characters.
-.PP
-When decoding text in such an alternate character set,
-.B nmh
-must be able to determine which characters are alphabetic, which
-are control characters, etc.  For many operating systems, this
-will require enabling the support for locales (such as setting
-the environment variable
-.B $LC_CTYPE
-to iso_8859_1).
-.RE
-.PP
 .B $MAILDROP
 .RS 5
 This variable tells
index 2f0e8ee..e4bd793 100644 (file)
@@ -1,4 +1,4 @@
-.TH MHBUILD %manext1% "March 21, 2013" "%nmhversion%"
+.TH MHBUILD %manext1% "January 23, 2014" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
@@ -21,6 +21,7 @@ mhbuild \- translate MIME composition draft
 .RB [ \-headerencoding 
 .IR encoding\-algorithm
 .RB " | " \-autoheaderencoding ]
+.RB [ \-dist ]
 .RB [ \-version ]
 .RB [ \-help ]
 .ad
@@ -78,6 +79,21 @@ switch
 is present, then the listing will show any \*(lqextra\*(rq information
 that is present in the message, such as comments in the
 \*(lqContent-Type\*(rq header.
+.SS "Simplified Attachment Interface"
+For users who wish to simply attach files to text content,
+.B mhbuild
+will scan the composition file for \*(lqAttach\*(rq headers.  An
+\*(lqAttach\*(rq header contains a filename that will be appended to the
+message using normal MIME encapsulation rules.  One filename is allowed
+per \*(lqAttach\*(rq header, but multiple \*(lqAttach\*(rq headers are
+allowed ber composition file.
+.PP
+These files will be appended after any other MIME content, including any
+content specified by
+.B mhbuild
+directives (see below).  See
+.IR send (1)
+for more details.
 .SS "Translating the Composition File"
 .B mhbuild
 is essentially a filter to aid in the composition of MIME
@@ -448,7 +464,9 @@ If a text content contains any 8\-bit characters (characters with the
 high bit set) and the character set is not specified as above, then
 .B mhbuild
 will assume the character set is of the type given by the
-environment variable MM_CHARSET.  If this environment variable is not
+standard
+.IR locale (1)
+environment variables.  If these environment variables are not
 set, then the character set will be labeled as \*(lqx-unknown\*(rq.
 .PP
 If a text content contains only 7\-bit characters and the character set
@@ -553,20 +571,11 @@ on file that already in MIME format.  The
 switch will cause
 .B mhbuild
 to exit without error if the input file already has valid MIME headers.
-.PP
-It is also possible to have the
-.B whatnow
-program invoke
-.B mhbuild
-automatically when a message is sent.  To do this, you must add the line
-.PP
-.RS 5
-automimeproc: 1
-.RE
-.PP
-to your
-.I \&.mh\(ruprofile
-file.
+The use of
+.B \-auto
+also enables the
+.B \-nodirectives
+switch.
 .PP
 Finally, you should consider adding this line to your profile:
 .PP
@@ -585,6 +594,14 @@ What now? list
 .RE
 .PP
 will work as you expect.
+.PP
+The
+.B \-dist
+switch is intended to be used by
+.BR dist .
+It will cause mhbuild to not generate any MIME headers in the composition
+file (such as \*(lqMIME-Version\*(rq or \*(lqContent-Type\*(rq), but it
+will still encode message headers according to RFC 2047.
 .SS "User Environment"
 Because the environment in which
 .B mhbuild
index 4ecb614..ac46c01 100644 (file)
@@ -1,4 +1,4 @@
-.TH MHPATH %manext1% "November 6, 2012" "%nmhversion%"
+.TH MHPATH %manext1% "January 20, 2014" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
@@ -115,6 +115,7 @@ is also useful in backquoted operations:
 /r/phyl/Mail
 .fi
 .RE
+.PP
 Because
 .B mhpath
 expands and sorts
@@ -138,12 +139,14 @@ mv `mhpath 501` `mhpath 500`
 .PP
 will do the trick.
 .PP
-Out of range message 0 is treated far more severely than large out of
-range message numbers.
+Out-of-range message 0 produces a different error message than large
+out-of-range message numbers.  But both cause
+.B mhpath
+to exit with non-zero status.
 .SH FILES
 .fc ^ ~
 .nf
-.ta \w'%etcdir%/ExtraBigFileName  'u
+.ta \w'ExtraBigProfileName  'u
 ^$HOME/\&.mh\(ruprofile~^The user profile
 .fi
 .SH "PROFILE COMPONENTS"
index f55fbfe..9cc44c1 100644 (file)
@@ -328,15 +328,15 @@ encounters a \*(lqcharset\*(rq parameter for
 this content, it checks if your terminal can display this character
 set natively.
 .B mhn
-checks this by examining the environment
-variable
-.BR $MM_CHARSET .
-If the value of this environment variable is equal
+checks this by examining the current character set defined by the
+.IR locale (1)
+environment variables.
+If the value of the locale character set is equal
 to the value of the charset parameter, then
 .B mhshow
 assumes it can
-display this content without any additional setup.  If this environment
-variable is not set,
+display this content without any additional setup.  If the locale is not
+set properly,
 .B mhshow
 will assume a value of \*(lqUS-ASCII\*(rq.
 If the character set cannot be displayed natively, then
index c1cac4b..245d45a 100644 (file)
@@ -350,16 +350,7 @@ Note that
 .B nmh
 will not invoke
 .B mhbuild
-automatically, unless you
-add this line to your
-.I \&.mh\(ruprofile
-file:
-.PP
-.RS 5
-automimeproc: 1
-.RE
-.PP
-Otherwise, you must specifically give the command
+automatically; you must specifically give the command
 .PP
 .RS 5
 What now? mime
index b9c94f4..17a702c 100644 (file)
@@ -73,9 +73,12 @@ these scan listings.
 .B Scan
 will only decode these fields if your
 terminal can natively display the character set used in the encoding.
-You should set the MM_CHARSET environment variable to your native
-character set, if it is not US-ASCII.  See the mh-profile(5) man
-page for details about this environment variable.
+You should set the appropriate
+.IR locale (1)
+environment variables to your native
+character set, if it is not US-ASCII.  See
+.IR locale (1)
+for more details on the appropriate environment variables.
 .PP
 The switch
 .BR \-reverse ,
index 83cf19a..c83a74f 100644 (file)
@@ -1,7 +1,7 @@
 .\"
 .\" %nmhwarning%
 .\"
-.TH SEND %manext1% "December 22, 2013" "%nmhversion%"
+.TH SEND %manext1% "January 23, 2014" "%nmhversion%"
 .SH NAME
 send \- send a message
 .SH SYNOPSIS
@@ -54,11 +54,6 @@ send \- send a message
 \&...]
 .RB [ \-version ]
 .RB [ \-help ]
-.RB [ \-attach
-.IR header-field-name ]
-.RB [ \-noattach ]
-.RB [ \-attachformat
-.IR 0 " | " 1 " | " 2 ]
 .ad
 .SH DESCRIPTION
 .B Send
@@ -83,24 +78,39 @@ profile component.  Most of the features attributed to
 are actually performed by
 .BR post .
 .PP
-By default the draft is scanned for a header named
-.IR Nmh-Attachment .
+Before
+.B send
+gives the message to
+.B post
+for delivery, the message is processed by
+.B mhbuild
+to perform any necessary MIME encoding of the outgoing message.  This
+can be changed by the
+.I buildmimeproc
+profile component.
+.B mhbuild
+is invoked with the
+.B \-auto
+switch, so
+.B mhbuild
+directives are not processed by default.  See
+.IR mhbuild (1)
+for more information.
+.PP
+.B mhbuild
+will scan the message draft for a header named
+.IR Attach .
 The draft is converted to a MIME message if one or more matches are found.
-This conversion occurs before all other processing.  The header name
-can be changed with the
-.B \-attach
-option.  This behavior can be disabled completely with the
-.B \-noattach
-option.  The
-.B whatnow
+This conversion occurs before all other processing.  The
+.IR whatnow (1)
 man page describes the user interface for managing MIME attachments via
 this mechanism.
 .PP
 The first part of the MIME message is the draft body if that body contains
 any non-blank characters.
-The body of each header field whose name matches the
-.I header-field-name
-is interpreted as a file name, and each file named is included as a separate
+The body of each
+.I Attach
+header field is interpreted as a file name, and each file named is included as a separate
 part in the MIME message.
 .PP
 Determination of the content MIME type inserted into the Content-Type
@@ -109,9 +119,9 @@ header for each part depends on how the
 installation was configured.  If a program, such as
 .B file
 with a
-.B --mime
+.B \-\-mime
 or
-.B -i
+.B \-i
 option, was found that can specify the type of a file as a MIME type
 string, then that will be used.  To determine if your
 .B nmh
@@ -135,54 +145,15 @@ if it contains characters outside of the ASCII range.  See
 .IR mhshow (1)
 for more details and example syntax.
 .PP
-Each part contains a name attribute that is the last component of the path name.
-A
-.I x-unix-mode
-attribute containing the file mode accompanies each part.
-Finally, a description attribute is generated by running the
-.I file
-command on the file.
-.PP
-The
-.B -attachformat
-option specifies the MIME header field formats:  a value of
-.B 0
-includes the
-.I x-unix-mode
-attribute as noted above.  A value of
-.BR 1 ,
-the default,
-suppresses that, puts the file name in the
-\*(lqContent-Description\*(rq header, and
-adds a \*(lqContent-Disposition\*(rq header.  A value of
-.B 2
-adds the file
-.I modification-date
-parameter to the \*(lqContent-Disposition\*(rq header.  You can
-specify one value in your profile, and override it for individual
-messages at the
-.I whatnow
-prompt.
-.PP
-Here are example message part headers, for an attachment, for each of the
-.B -attachformat
-values:
+Each attached MIME part contains a 
+\*(lqContent-Description\*(rq header that includes the filename, and
+adds a \*(lqContent-Disposition\*(rq header.
+Here is an example of MIME part headers for an attachment:
 .PP
 .nf
--attachformat 0:
-Content-Type: text/plain; name="VERSION"; x-unix-mode="0644";
-       charset="us-ascii"
-Content-Description: ASCII text
-
--attachformat 1:
 Content-Type: text/plain; name="VERSION"; charset="us-ascii"
 Content-Description: VERSION
 Content-Disposition: attachment; filename="VERSION"
-
--attachformat 2:
-Content-Type: text/plain; name="VERSION"; charset="us-ascii"
-Content-Description: VERSION
-Content-Disposition: attachment; filename="VERSION"; modification-date="Mon, 19 Dec 2005 22:39:51 -0600"
 .fi
 .PP
 If
@@ -517,8 +488,6 @@ for more information.
 .RB ` \-noverbose '
 .RB ` \-nowatch '
 .RB ` "\-width\ 72" '
-.RB ` "\-attach\ Nmh-Attachment" '
-.RB ` "\-attachformat\ 1" '
 .fi
 .SH CONTEXT
 None
index c69a7d7..04589fb 100644 (file)
@@ -92,14 +92,15 @@ specify a transfer encoding (such as MIME quoted-printable or
 base64) or specify a character set that
 .B show
 doesn't believe
-can be displayed natively.  The environment variable
-.B $MM_CHARSET
+can be displayed natively.  The appropriate
+.IR locale (1)
+environment variables
 should be set to the terminal's native character set to avoid
 gratuitous invocations of the
 .IR showmimeproc .
 See the
-.IR mh-profile (5)
-man page for details about this environment variable.
+.IR locale (1)
+man page for details about these environment variables.
 .PP
 The option
 .B \-checkmime
index 367a326..c1f735b 100644 (file)
@@ -21,9 +21,6 @@ whatnow \- prompting front-end for sending messages
 .RI [ file ]
 .RB [ \-version ]
 .RB [ \-help ]
-.RB [ \-attach
-.IR header-field-name ]
-.RB [ \-noattach ]
 .ad
 .SH DESCRIPTION
 .B Whatnow
@@ -228,9 +225,6 @@ commands for managing MIME attachments.
 ^Editor:~^To override the default editor
 ^<lasteditor>\-next:~^To name an editor to be used after exit
 ^~^from <lasteditor>
-^automimeproc:~^If value is 1, and the draft is a MIME
-^~^composition file, then automatically call
-^~^buildmimeproc prior to sending.
 ^buildmimeproc:~^Program to translate MIME composition files
 ^fileproc:~^Program to refile the message
 ^lproc:~^Program to list the contents of a message
@@ -243,7 +237,6 @@ commands for managing MIME attachments.
 .SH DEFAULTS
 .nf
 .RB ` \-prompt "' defaults to \*(lqWhat\ Now?\ \*(rq"
-.RB ` \-attach "' defaults to \*(lqNmh-Attachment\*(rq"
 .fi
 .SH BUGS
 If the initial edit fails,
index e43459e..4f2eeba 100644 (file)
@@ -8,9 +8,8 @@
  */
 
 #include <h/mh.h>
-#ifdef HAVE_LANGINFO_H
-# include <langinfo.h>
-#endif
+
+#include <langinfo.h>
 
 
 /*
 char *
 get_charset ()
 {
-    char *charset = getenv ("MM_CHARSET");
-#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
-    if (!charset)
-       charset = norm_charmap(nl_langinfo (CODESET));
-#endif
-    return charset;
+    return norm_charmap(nl_langinfo (CODESET));
 }
 
 
index d7d87e4..5224af4 100644 (file)
@@ -53,8 +53,6 @@ context_save (void)
     sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
 
     if (action == 0)
-       /* This must be _exit(), not exit(), because the child didn't
-          call unregister_for_removal() in m_chkids(). */
        _exit (0);              /* we are child, time to die */
 }
 
@@ -85,8 +83,6 @@ m_chkids (void)
            break;
 
        case 0:
-           /* It's not necessary to call unregister_for_removal(0)
-               because the child calls _exit() in context_save(). */
            setgid (getgid ());
            setuid (getuid ());
            break;
index 75adc08..970e71e 100644 (file)
@@ -364,11 +364,7 @@ compile_error(char *str, char *cp)
     usr_fstring[errpos] = '\0';
 
     for (i = errpos-errctx; i < errpos; i++) {
-#ifdef LOCALE
        if (iscntrl((unsigned char) usr_fstring[i]))
-#else
-       if (usr_fstring[i] < 32)
-#endif
            usr_fstring[i] = '_';
     }
 
index 9b84861..e4d79d5 100644 (file)
@@ -47,7 +47,6 @@ match (char *str, char *sub)
     int c1, c2;
     char *s1, *s2;
 
-#ifdef LOCALE
     while ((c1 = *sub)) {
        c1 = (isascii((unsigned char) c1) && isalpha((unsigned char) c1) &&
              isupper((unsigned char) c1)) ? tolower((unsigned char) c1) : c1;
@@ -71,19 +70,6 @@ match (char *str, char *sub)
        if (! c1)
            return 1;
     }
-#else
-    while ((c1 = *sub)) {
-       while ((c2 = *str++) && (c1 | 040) != (c2 | 040))
-           ;
-       if (! c2)
-           return 0;
-       s1 = sub + 1; s2 = str;
-       while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040))
-           ;
-       if (! c1)
-           return 1;
-    }
-#endif
     return 1;
 }
 
index db593f8..ee4bd9e 100644 (file)
@@ -112,7 +112,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook)
 
            if (unlink_msgs) {
                /* just unlink the messages */
-               if (m_unlink (dp) == -1) {
+               if (unlink (dp) == -1) {
                    admonish (dp, "unable to unlink");
                    retval = -1;
                    continue;
index 6b76b7b..7023402 100644 (file)
@@ -26,12 +26,7 @@ gans (char *prompt, struct swit *ansp)
            if (i == EOF)
                return 0;
            if (cp < &ansbuf[sizeof ansbuf - 1]) {
-#ifdef LOCALE
                i = (isalpha(i) && isupper(i)) ? tolower(i) : i;
-#else
-               if (i >= 'A' && i <= 'Z')
-                   i += 'a' - 'A';
-#endif
                *cp++ = i;
            }
        }
index 1a562f9..01d7ae4 100644 (file)
@@ -335,7 +335,7 @@ lkclose_dot (int fd, const char *file)
 
     lockname (file, &lkinfo, 0);       /* get name of lock file */
 #if !defined(HAVE_LIBLOCKFILE)
-    (void) m_unlink (lkinfo.curlock);  /* remove lock file      */
+    unlink (lkinfo.curlock);           /* remove lock file      */
 #else
     lockfile_remove(lkinfo.curlock);
 #endif /* HAVE_LIBLOCKFILE */
@@ -513,7 +513,7 @@ lkopen_dot (const char *file, int access, mode_t mode)
                    
                    /* check for stale lockfile, else sleep */
                    if (curtime > st.st_ctime + RSECS)
-                       (void) m_unlink (lkinfo.curlock);
+                       unlink (lkinfo.curlock);
                    else
                        sleep (5);
                }
@@ -543,18 +543,17 @@ static int
 lockit (struct lockinfo *li)
 {
     int fd;
-    char *curlock, *tmpfile;
+    char *curlock, *tmplock;
 
 #if 0
     char buffer[128];
 #endif
 
     curlock = li->curlock;
+    tmplock = li->tmplock;
 
-    if ((tmpfile = m_mktemp(li->tmplock, &fd, NULL)) == NULL) {
-        advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+    if ((fd = mkstemp(tmplock)) == -1)
        return -1;
-    }
 
 #if 0
     /* write our process id into lock file */
@@ -568,8 +567,8 @@ lockit (struct lockinfo *li)
      * Now try to create the real lock file
      * by linking to the temporary file.
      */
-    fd = link(tmpfile, curlock);
-    (void) m_unlink(tmpfile);
+    fd = link(tmplock, curlock);
+    unlink(tmplock);
 
     return (fd == -1 ? -1 : 0);
 }
index f05271f..da6730d 100644 (file)
@@ -19,11 +19,7 @@ m_atoi (char *str)
     char *cp;
 
     for (i = 0, cp = str; *cp; cp++) {
-#ifdef LOCALE
        if (!isdigit((unsigned char) *cp))
-#else
-       if (*cp < '0' || *cp > '9')
-#endif
            return 0;
 
        i *= 10;
index 5e24a03..c34c409 100644 (file)
@@ -23,6 +23,6 @@ m_backup (char *file)
        snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
                BACKUP_PREFIX, cp);
 
-    (void) m_unlink(buffer);
+    unlink(buffer);
     return buffer;
 }
index 62268fb..d708006 100644 (file)
@@ -286,14 +286,9 @@ m_conv (struct msgs *mp, char *str, int call)
            return BADNUM;
     }
 
-#ifdef LOCALE
     /* doesn't enforce lower case */
     for (bp = buf; (isalpha((unsigned char) *cp) || *cp == '.')
            && (bp - buf < (int) sizeof(buf) - 1); )
-#else
-    for (bp = buf; ((*cp >= 'a' && *cp <= 'z') || *cp == '.')
-           && (bp - buf < (int) sizeof(buf) - 1); )
-#endif /* LOCALE */
     {
        *bp++ = *cp++;
     }
index ac05306..ca4ab29 100644 (file)
@@ -7,11 +7,8 @@
  */
 
 #include <h/mh.h>
-#include <h/utils.h>
-#include <h/signals.h>
-
-static void register_for_removal(const char *);
 
+static char *get_temp_dir();
 
 /*  Create a temporary file.  If pfx_in is null, the temporary file
  *  will be created in the temporary directory (more on that later).
@@ -29,7 +26,7 @@ static void register_for_removal(const char *);
  *
  *  When pfx_in is null, the temporary directory is determined as
  *  follows, in order:
- *
+ *  
  *    MHTMPDIR envvar
  *    TMPDIR envvar
  *    TMP envvar
@@ -61,14 +58,10 @@ m_mktemp (
     }
 
     fd = mkstemp(tmpfil);
-
     if (fd < 0) {
         umask(oldmode);
         return NULL;
     }
-
-    register_for_removal(tmpfil);
-
     if (fd_ret != NULL) {
         *fd_ret = fd;
         keep_open = 1;
@@ -77,7 +70,7 @@ m_mktemp (
         FILE *fp = fdopen(fd, "w+");
         if (fp == NULL) {
             int olderr = errno;
-            (void) m_unlink(tmpfil);
+            unlink(tmpfil);
             close(fd);
             errno = olderr;
             umask(oldmode);
@@ -97,7 +90,7 @@ m_mktemp (
  * by created based on a given pathname.  Although m_mktemp() technically
  * supports this, this version is when the directory is defined by
  * a separate variable from the prefix, eliminating the caller from having
- * to do string manipulation to generate the desired pathname prefix.
+ * to do string manipulation to generate the desired. pathname prefix.
  *
  * The pfx_in parameter specifies a basename prefix for the file.  If dir_in
  * is NULL, then the defined temporary directory (see comments to m_mktemp()
@@ -133,7 +126,7 @@ m_mktemp2 (
 }
 
 
-char *
+static char *
 get_temp_dir()
 {
     /* Ignore envvars if we are setuid */
@@ -150,125 +143,3 @@ get_temp_dir()
     }
     return m_maildir("");
 }
-
-
-/*
- * Array of files (full pathnames) to remove on process exit.
- * Instead of removing slots from the array, just set to NULL
- * to indicate that the file should no longer be removed.
- */
-static svector_t exit_filelist = NULL;
-
-/*
- * Register a file for removal at program termination.
- */
-static void
-register_for_removal(const char *pathname) {
-    if (exit_filelist == NULL) exit_filelist = svector_create(20);
-    (void) svector_push_back(exit_filelist, add(pathname, NULL));
-}
-
-/*
- * Unregister all files that were registered to be removed at program
- * termination.  When called with remove_files of 0, this function is
- * intended for use by one of the programs after a fork(3) without a
- * subsequent call to one of the exec(3) functions or _exit(3).  When
- * called with non-0 remove_files argument, it is intended for use by
- * an atexit() function.
- *
- * Right after a fork() and before calling exec() or _exit(), if the
- * child catches one of the appropriate signals, it will remove
- * all the registered temporary files.  Some of those may be needed by
- * the parent.  Some nmh programs ignore or block some of the signals
- * in the child right after fork().  For the other programs, rather
- * than complicate things by preventing that, just take the chance
- * that it might happen.  It is harmless to attempt to unlink a
- * temporary file twice, assuming another one wasn't created too
- * quickly created with the same name.
- */
-void
-unregister_for_removal(int remove_files) {
-    if (exit_filelist) {
-        size_t i;
-
-        for (i = 0; i < svector_size(exit_filelist); ++i) {
-            char *filename = svector_at(exit_filelist, i);
-
-            if (filename) {
-                if (remove_files) (void) unlink(filename);
-                free(filename);
-            }
-        }
-
-        svector_free(exit_filelist);
-        exit_filelist = NULL;
-    }
-}
-
-/*
- * If the file was registered for removal, deregister it.  In
- * any case, unlink it.
- */
-int
-m_unlink(const char *pathname) {
-    if (exit_filelist) {
-        char **slot = svector_find(exit_filelist, pathname);
-
-        if (slot  &&  *slot) {
-            free(*slot);
-            *slot = NULL;
-        }
-    }
-
-    return unlink(pathname);
-    /* errno should be set to ENOENT if file was not found */
-}
-
-/*
- * Remove all registered temporary files.
- */
-void
-remove_registered_files_atexit() {
-    unregister_for_removal(1);
-}
-
-/*
- * Remove all registered temporary files.  Suitable for use as a
- * signal handler.  If the signal is one of the usual process
- * termination signals, calls exit().  Otherwise, disables itself
- * by restoring the default action and then re-raises the signal,
- * in case the use was expecting a core dump.
- */
-void
-remove_registered_files(int sig) {
-    struct sigaction act;
-
-    /*
-     * Ignore this signal for the duration.  And we either exit() or
-     * disable this signal handler below, so don't restore this handler.
-     */
-    act.sa_handler = SIG_IGN;
-    (void) sigemptyset(&act.sa_mask);
-    act.sa_flags = 0;
-    (void) sigaction(sig, &act, 0);
-
-    if (sig == SIGHUP || sig == SIGINT || sig == SIGQUIT || sig == SIGTERM) {
-        /*
-         * We don't need to call remove_registered_files_atexit() if
-         * it was registered with atexit(), but let's not assume that.
-         * It's harmless to call it twice.
-         */
-        remove_registered_files_atexit();
-
-        exit(1);
-    } else {
-        act.sa_handler = SIG_DFL;
-        (void) sigemptyset(&act.sa_mask);
-        act.sa_flags = 0;
-        (void) sigaction(sig, &act, 0);
-
-        remove_registered_files_atexit();
-
-        (void) raise(sig);
-    }
-}
diff --git a/sbr/mime_type.c b/sbr/mime_type.c
new file mode 100644 (file)
index 0000000..be79109
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * mime_type.c -- routine to determine the MIME Content-Type of a file
+ *
+ * This code is Copyright (c) 2014, 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 <h/utils.h>
+#include <h/tws.h>
+
+#ifdef MIMETYPEPROC
+static char *get_file_info(const char *, const char *);
+#endif /* MIMETYPEPROC */
+
+/*
+ * Try to use external command to determine mime type, and possibly
+ * encoding.  If that fails try using the filename extension.  Caller
+ * is responsible for free'ing returned memory.
+ */
+char *
+mime_type(const char *file_name) {
+    char *content_type = NULL;  /* mime content type */
+    char *p;
+    static int loaded_defaults = 0;
+
+#ifdef MIMETYPEPROC
+    char *mimetype;
+
+    if ((mimetype = get_file_info(MIMETYPEPROC, file_name))) {
+#ifdef MIMEENCODINGPROC
+        /* Try to append charset for text content. */
+        char *mimeencoding;
+
+        if (strncasecmp(mimetype, "text", 4) == 0) {
+            if ((mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) {
+                content_type = concat(mimetype, "; charset=", mimeencoding,
+                                      NULL);
+            } else {
+                content_type = strdup(mimetype);
+            }
+        } else {
+            content_type = strdup(mimetype);
+        }
+#else  /* MIMEENCODINGPROC */
+        content_type = strdup(mimetype);
+#endif /* MIMEENCODINGPROC */
+    }
+#endif /* MIMETYPEPROC */
+
+    /*
+     * If we didn't get the MIME type from the contents (or we don't support
+     * the necessary command) then use the mhshow suffix.
+     */
+
+    if (content_type == NULL) {
+       struct node *np;                /* Content scan node pointer */
+       FILE *fp;                       /* File pointer for mhn.defaults */
+
+       if (! loaded_defaults &&
+                       (fp = fopen(p = etcpath("mhn.defaults"), "r"))) {
+           loaded_defaults = 1;
+           readconfig(NULL, fp, p, 0);
+           fclose(fp);
+       }
+
+       if ((p = strrchr(file_name, '.')) != NULL) {
+           for (np = m_defs; np; np = np->n_next) {
+               if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 &&
+                   strcasecmp(p, np->n_field ? np->n_field : "") == 0) {
+                   content_type = strdup(np->n_name + 14);
+                   break;
+               }
+           }
+       }
+
+       /*
+        * If we didn't match any filename extension, try to infer the
+        * content type. If we have binary, assume application/octet-stream;
+        * otherwise, assume text/plain.
+        */
+
+       if (content_type == NULL) {
+           FILE *fp;
+           int binary = 0, c;
+
+           if (!(fp = fopen(file_name, "r"))) {
+               advise (NULL, "unable to access file \"%s\"", file_name);
+               return NULL;
+           }
+
+           while ((c = getc(fp)) != EOF) {
+               if (! isascii(c)) {
+                   binary = 1;
+                   break;
+               }
+           }
+
+           fclose(fp);
+
+           content_type =
+               strdup(binary ? "application/octet-stream" : "text/plain");
+       }
+    }
+
+    return content_type;
+}
+
+
+#ifdef MIMETYPEPROC
+/*
+ * Get information using proc about a file.
+ */
+static char *
+get_file_info(const char *proc, const char *file_name) {
+    char *cmd, *cp;
+    char *quotec = "'";
+
+    if ((cp = strchr(file_name, '\''))) {
+        /* file_name contains a single quote. */
+        if (strchr(file_name, '"')) {
+            advise(NULL, "filenames containing both single and double quotes "
+                   "are unsupported for attachment");
+            return NULL;
+        } else {
+            quotec = "\"";
+        }
+    }
+
+    cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
+    if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
+        FILE *fp;
+
+        if ((fp = popen(cmd, "r")) != NULL) {
+            char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
+
+            buf[0] = '\0';
+            if (fgets(buf, sizeof buf, fp)) {
+                char *eol;
+
+                /* Skip leading <filename>:<whitespace>, if present. */
+                if ((cp = strchr(buf, ':')) != NULL) {
+                    ++cp;
+                    while (*cp  &&  isblank((unsigned char) *cp)) {
+                        ++cp;
+                    }
+                } else {
+                    cp = buf;
+                }
+
+                /* Truncate at newline (LF or CR), if present. */
+                if ((eol = strpbrk(cp, "\n\r")) != NULL) {
+                    *eol = '\0';
+                }
+            } else if (buf[0] == '\0') {
+                /* This can happen on Cygwin if the popen()
+                   mysteriously fails.  Return NULL so that the caller
+                   will use another method to determine the info. */
+                free (cp);
+                cp = NULL;
+            }
+
+            (void) pclose(fp);
+        } else {
+            advise(NULL, "no output from %s", cmd);
+        }
+
+        free(cmd);
+    } else {
+        advise(NULL, "concat with \"%s\" failed, out of memory?", proc);
+    }
+
+    return cp  ?  strdup(cp)  :  NULL;
+}
+#endif /* MIMETYPEPROC */
index 39c58ac..b4e3f49 100644 (file)
@@ -37,9 +37,6 @@ push(void)
            SIGNAL (SIGTTIN, SIG_IGN);
            SIGNAL (SIGTTOU, SIG_IGN);
 #endif
-
-           unregister_for_removal(0);
-
            freopen ("/dev/null", "r", stdin);
            freopen ("/dev/null", "w", stdout);
            break;
index 5b06dcd..83753af 100644 (file)
@@ -91,7 +91,7 @@ priv:
                    rewind(fp);
                    ftruncate(fileno(fp), 0);
                } else if ((fp = lkfopendata (seqfile, "w")) == NULL
-                       && (m_unlink (seqfile) == -1 ||
+                       && (unlink (seqfile) == -1 ||
                            (fp = lkfopendata (seqfile, "w")) == NULL)) {
                    admonish (attr, "unable to write");
                    goto priv;
@@ -118,7 +118,7 @@ priv:
         * public sequences, then remove that file.
         */
        if (!is_readonly(mp))
-           (void) m_unlink (seqfile);
+           unlink (seqfile);
     }
 
     /*
index 7645c1c..eb26e63 100644 (file)
@@ -10,9 +10,6 @@
 #include <h/mh.h>
 #include <h/signals.h>
 
-/* sbr/m_mktemp.c */
-extern void remove_registered_files(int);
-
 
 /*
  * A version of the function `signal' that uses reliable
@@ -81,30 +78,3 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func)
     return (oact.sa_handler);
 }
 
-
-/*
- * For use by nmh_init().
- */
-int
-setup_signal_handlers() {
-    /*
-     * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
-     * files when the user terminates the process early.  And also a
-     * few other common signals that can be thrown due to bugs, stack
-     * overflow, etc.
-     */
-
-    if (SIGNAL(SIGHUP,  remove_registered_files) == SIG_ERR  ||
-        SIGNAL(SIGINT,  remove_registered_files) == SIG_ERR  ||
-        SIGNAL(SIGQUIT, remove_registered_files) == SIG_ERR  ||
-        SIGNAL(SIGTERM, remove_registered_files) == SIG_ERR  ||
-        SIGNAL(SIGILL,  remove_registered_files) == SIG_ERR  ||
-#       ifdef SIGBUS
-        SIGNAL(SIGBUS,  remove_registered_files) == SIG_ERR  ||
-#       endif
-        SIGNAL(SIGSEGV, remove_registered_files) == SIG_ERR) {
-        return NOTOK;
-    }
-
-    return OK;
-}
index 5da5e76..500b036 100644 (file)
@@ -9,11 +9,6 @@
 
 #include <h/mh.h>
 
-#ifndef LOCALE
-# define TO_LOWER 040
-# define NO_MASK  000
-#endif
-
 
 int
 uprf (char *c1, char *c2)
@@ -25,16 +20,11 @@ uprf (char *c1, char *c2)
 
     while ((c = *c2++))
     {
-#ifdef LOCALE
        c &= 0xff;
        mask = *c1 & 0xff;
        c = (isalpha(c) && isupper(c)) ? tolower(c) : c;
        mask = (isalpha(mask) && isupper(mask)) ? tolower(mask) : mask;
        if (c != mask)
-#else
-       mask = (isalpha(c) && isalpha(*c1)) ?  TO_LOWER : NO_MASK;
-       if ((c | mask) != (*c1 | mask))
-#endif
            return 0;
        else
            c1++;
index d17bad9..7f0760a 100644 (file)
 #include <h/utils.h>
 #include <fcntl.h>
 
-/* sbr/signals.c */
-extern int setup_signal_handlers();
-
-/* sbr/m_mktemp.c */
-extern void remove_registered_files_atexit();
-
-
 /*
  * We allocate space for messages (msgs array)
  * this number of elements at a time.
@@ -324,33 +317,3 @@ nmh_strcasestr (const char *s1, const char *s2) {
 
     return NULL;
 }
-
-
-int
-nmh_init(const char *argv0, int read_context) {
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-
-    invo_name = r1bindex ((char *) argv0, '/');
-
-    if (setup_signal_handlers()) {
-        admonish("sigaction", "unable to set up signal handlers");
-    }
-
-    /* POSIX atexit() does not define any error conditions. */
-    if (atexit(remove_registered_files_atexit)) {
-        admonish("atexit", "unable to register atexit function");
-    }
-
-    if (read_context) {
-        context_read();
-        return OK;
-    } else {
-        int status = context_foil(NULL);
-        if (status != OK) {
-            advise("", "failed to create minimal profile/conext");
-        }
-        return status;
-    }
-}
index 10058d4..ca8c894 100644 (file)
@@ -174,24 +174,6 @@ svector_at (svector_t vec, size_t i) {
     return vec->strs[i];
 }
 
-/*
- * Return address of first element that stringwise matches s.
- * The caller can replace the contents of the return address.
- */
-char **
-svector_find (svector_t vec, const char *s) {
-    size_t i;
-    char **str = vec->strs;
-
-    for (i = 0; i < vec->size; ++i, ++str) {
-        if (*str  &&  ! strcmp(*str, s)) {
-            return str;
-        }
-    }
-
-    return NULL;
-}
-
 char **
 svector_strs (svector_t vec) {
     return vec->strs;
index 13db440..be8b25d 100644 (file)
@@ -23,7 +23,7 @@ test -z "$MH_INST_DIR"  &&  MH_INST_DIR="${MH_TEST_DIR}/inst"
 export MH_INST_DIR
 
 unset MHBUILD MHCONTEXT MHMTSUSERCONF MHN MHSHOW MHSTORE
-unset MHLDEBUG MHPDEBUG MHWDEBUG MM_CHARSET PAGER
+unset MHLDEBUG MHPDEBUG MHWDEBUG PAGER
 
 #### Use a test dir for tmp files when MHTMPDIR applies.
 MHTMPDIR=$MH_TEST_DIR/Mail
index 2bb1d30..c082b5e 100755 (executable)
@@ -384,5 +384,26 @@ EOF
 test_dist +inbox 1 -noedit -to somebody@example.com -fcc +outbox
 run_test 'scan +outbox -width 6 2' '   2 '
 
+#
+# Check that dist encodes headers using RFC-2047 properly
+#
+
+LC_ALL=en_US.UTF-8; export LC_ALL
+
+cat >"$expected" <<EOF
+From: Test1 <test1@example.com>
+To: Some User <user@example.com>
+Date: Fri, 29 Sep 2006 00:00:00
+Message-Id: 1@test.nmh
+Subject: Testing message 1
+Resent-From: =?UTF-8?Q?Mr_F=C3=B8o_Bar?= <foo@bar.com>
+Resent-To: =?UTF-8?Q?Mr_Nobod=C3=BF?= <nobody@nowhere.com>
+Resent-Date:
+
+This is message number 1
+EOF
+
+test_dist +inbox 1 -noedit -from 'Mr Føo Bar <foo@bar.com>' \
+         -to 'Mr Nobodÿ <nobody@nowhere.com>' -fcc +outbox
 
 exit ${failed:-0}
index 4eacc6e..9f65269 100755 (executable)
@@ -14,9 +14,10 @@ fi
 
 setup_test
 
+LC_ALL=en_US.UTF-8; export LC_ALL
+
 draft="$MH_TEST_DIR/$$.draft"
 expected="$MH_TEST_DIR/$$.expected"
-actual="$MH_TEST_DIR/$$.actual"
 
 #
 # Test out a simple draft, one part.
@@ -30,9 +31,9 @@ Attach: ${srcdir}/test/mhbuild/tiny.jpg
 ------
 EOF
 
-mhbuild "$draft"
+run_prog mhbuild "$draft"
 
-cat > "$actual" <<EOF
+cat > "$expected" <<EOF
 To: Mr Test <mrtest@example.com>
 cc:
 Fcc: +outbox
@@ -45,7 +46,7 @@ Content-Transfer-Encoding: base64
 /9g=
 EOF
 
-check "$draft" "$actual"
+check "$draft" "$expected"
 
 #
 # Check out more common case, one (or more) attachments
@@ -61,12 +62,210 @@ Attach: ${srcdir}/test/mhbuild/tiny.jpg
 This is a test
 EOF
 
-mhbuild "$draft"
+run_prog mhbuild "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a test
+
+------- =_aaaaaaaaaa0
+Content-Type: image/jpeg; name="tiny.jpg"
+Content-Description: tiny.jpg
+Content-Disposition: attachment; filename="tiny.jpg"
+Content-Transfer-Encoding: base64
 
-cat "$draft"
+/9g=
+
+------- =_aaaaaaaaaa0--
+EOF
+
+check "$draft" "$expected"
 
 #
-# Two parts, one attachment
+# An empty Attach header
 #
 
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Attach:
+------
+This is a test of an empty attach header.
+EOF
+
+run_prog mhbuild "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a test of an empty attach header.
+EOF
+
+check "$draft" "$expected"
+
+#
+# Check a completely empty message
+#
+
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: Test of an empty body
+EOF
+
+run_prog mhbuild "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: Test of an empty body
+MIME-Version: 1.0
+Content-Type: text/plain
+EOF
+
+check "$draft" "$expected"
+
+#
+# Make sure we fail if we run into a MIME-Version header
+#
+
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: Test of an already-MIMEified message
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a preformatted MIME content test.
+EOF
+
+set +e
+run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field"
+set -e
+
+#
+# Run it again using -auto
+#
+
+run_prog mhbuild -auto "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: Test of an already-MIMEified message
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a preformatted MIME content test.
+EOF
+
+check "$draft" "$expected"
+
+#
+# Make sure -dist does nothing but encode headers
+#
+
+cat > "$draft" <<EOF
+To: Señor Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: An empty dist test
+EOF
+
+run_prog mhbuild -dist "$draft"
+
+cat > "$expected" <<EOF
+To: =?UTF-8?Q?Se=C3=B1or_Test?= <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: An empty dist test
+EOF
+
+check "$draft" "$expected"
+
+#
+# Two parts, one attachment; make sure mixing of multiparts at different
+# levels works
+#
+
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: A more complete multipart test
+Attach: ${srcdir}/test/mhbuild/tiny.jpg
+--------
+#begin alternative
+#<text/plain
+This is some tëxt.
+#<text/html
+<html>
+<body>
+This is some HTML tëxt.
+</body>
+</html>
+#end
+EOF
+
+run_prog mhbuild "$draft"
+
+cat > "$expected" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Subject: A more complete multipart test
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+
+------- =_aaaaaaaaaa0
+Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
+
+------- =_aaaaaaaaaa1
+Content-Type: text/plain; charset="UTF-8"
+Content-Transfer-Encoding: quoted-printable
+
+This is some t=C3=ABxt.
+
+------- =_aaaaaaaaaa1
+Content-Type: text/html; charset="UTF-8"
+Content-Transfer-Encoding: quoted-printable
+
+<html>
+<body>
+This is some HTML t=C3=ABxt.
+</body>
+</html>
+
+------- =_aaaaaaaaaa1--
+
+------- =_aaaaaaaaaa0
+Content-Type: image/jpeg; name="tiny.jpg"
+Content-Description: tiny.jpg
+Content-Disposition: attachment; filename="tiny.jpg"
+Content-Transfer-Encoding: base64
+
+/9g=
+
+------- =_aaaaaaaaaa0--
+EOF
+
+check "$draft" "$expected"
+
 exit ${failed:-0}
index e4a7c4e..033a2ef 100755 (executable)
@@ -54,7 +54,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Nmh-Attachment: $MH_TEST_DIR/attachment.txt
+Attach: $MH_TEST_DIR/attachment.txt
 
 This is a test.
 EOF
@@ -91,7 +91,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Nmh-Attachment: $MH_TEST_DIR/attachment.txt
+Attach: $MH_TEST_DIR/attachment.txt
 
 Â¡Ay, caramba!
 EOF
index 043d95e..ff9fd40 100755 (executable)
@@ -292,6 +292,8 @@ RCPT TO:<recipient@example.com>
 DATA
 To: recipient@example.com
 From: sender8@localhost
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 Message-ID:
 
index f75e203..ea00b81 100755 (executable)
@@ -263,7 +263,7 @@ echo 13 >"$expected"
 set +e
 
 # Don't use run_prog here because it loses the environment setting.
-LC_CTYPE=en_US.UTF-8 pick -subject foobar 13 >"$actual" 2>&1
+LC_ALL=en_US.UTF-8 pick -subject foobar 13 >"$actual" 2>&1
 set -e
 check "$expected" "$actual"
 
index 544af66..6ca8f97 100755 (executable)
@@ -32,6 +32,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -122,6 +124,8 @@ cat > "${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 Message-ID:
 
@@ -145,6 +149,8 @@ cat > "${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 Message-ID:
 
index afcd131..73b9aa1 100755 (executable)
@@ -30,6 +30,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -94,6 +96,8 @@ cat > "${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -118,6 +122,8 @@ cat > "${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -141,6 +147,8 @@ cat > "${testname}.expected1" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -157,6 +165,8 @@ Subject: Test
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
index 62c1863..664346d 100755 (executable)
@@ -86,6 +86,8 @@ cat >"${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Blind List: ;
 Subject: blind list test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of a blind list.
@@ -106,6 +108,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Blind List: ;
 Subject: blind list test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of a blind list.
@@ -129,6 +133,8 @@ cat >"${testname}.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: "named.list" <one@example.com>, "named.list" <two@example.com>
 Subject: named list test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of a named list.
index 74ef5e1..c198007 100755 (executable)
@@ -34,6 +34,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
@@ -84,6 +86,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test
index e1a6354..fe8d5fd 100755 (executable)
@@ -51,6 +51,8 @@ From: Mr Nobody <nobody@example.com>
 To: Somebody One <somebody1@example.com>,
     Somebody Two <somebody2@example.com>
 Subject: Test Bcc
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of Bcc recipients.
@@ -71,6 +73,8 @@ From: Mr Nobody <nobody@example.com>
 To: Somebody One <somebody1@example.com>,
     Somebody Two <somebody2@example.com>
 Subject: Test Bcc
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of Bcc recipients.
index f2bbda6..d9480da 100755 (executable)
@@ -36,6 +36,8 @@ From: Mr Nobody <nobody@example.com>
 To: Somebody One <somebody1@example.com>,
     Somebody Two <somebody2@example.com>
 Subject: Test Dcc
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of Dcc recipients.
index 7d3288b..b9e75ce 100755 (executable)
@@ -39,6 +39,8 @@ From: Mr Nobody One <nobody1@example.com>,
 Sender: Mr Nobody Three <nobody3@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Sender test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test of the Sender header.
@@ -73,6 +75,8 @@ From: Mr Nobody One <nobody1@example.com>,
 Sender: Mr Nobody Three <nobody3@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Envelope-From test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a test of the Envelope-From header.
@@ -106,6 +110,8 @@ From: Mr Nobody One <nobody1@example.com>,
       Mr Nobody Two <nobody2@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Envelope-From and Sender test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 Sender: nobody4@example.com
 
@@ -137,6 +143,8 @@ DATA
 From: Mr Nobody One <nobody1@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Solo Envelope-From test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a solo test of the Envelope-From header.
@@ -167,6 +175,8 @@ DATA
 From: Mr Nobody One <nobody1@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Blank Envelope-From test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a blank test of the Envelope-From header.
index 2fdd9de..052e3db 100755 (executable)
@@ -34,6 +34,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Fcc test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a fcc test
@@ -47,6 +49,8 @@ cat > "${testname}.msg.expected" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody Else <somebody@example.com>
 Subject: Fcc test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is a fcc test
index d5e39ae..59134b4 100755 (executable)
@@ -33,6 +33,8 @@ DATA
 From: Mr Nobody <nobody@example.com>
 To: our-group: ;
 Subject: Group test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of group recipients.
index 4fe3e85..f7d1a13 100755 (executable)
@@ -34,6 +34,8 @@ From: Mr Nobody <nobody@example.com>
 To: Somebody One <somebody1@example.com>,
     Somebody Two <somebody2@example.com>
 Subject: Test multiple
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
 Date:
 
 This is test of multiple recipients.
index c78a4d2..fb9747d 100755 (executable)
@@ -94,8 +94,8 @@ Message-Id: 12@test.nmh
 Subject: =?UTF-8?B?MjAxMyBOZXcgWWVhcuKAmXMgRGVhbHMhIFN0YXJ0IHRoZSB5ZWFy?=
        =?UTF-8?B?IHJpZ2h0IHdpdGggYmlnIHNhdmluZ3M=?=
 
-This message has an encoded Subject with an invalid character for the
-ISO-8859-1 character set, but it (U+2019) is valid UTF-8.
+This message has an encoded Subject with an invalid character for
+single-byte character sets, but it (U+2019) is valid UTF-8.
 EOF
 
 if test "$ICONV_ENABLED" -eq 1; then
@@ -103,8 +103,8 @@ if test "$ICONV_ENABLED" -eq 1; then
   12  12/31 Test12             2013 New Year?s Deals! Start the year right
 EOF
 
-    # Don't use run_prog here because it loses those environment settings.
-    LC_CTYPE=ISO-8859-1 MM_CHARSET=ISO-8859-1 scan -width 75 last >"$actual"
+    # Don't use run_prog here because it loses the environment setting.
+    LC_ALL=C scan -width 75 last >"$actual"
     check "$expected" "$actual"
 fi
 
@@ -132,15 +132,16 @@ else
     echo "Unsupported width for U+2019: $width"
 fi
 
-LC_CTYPE=en_US.UTF-8 MM_CHARSET=UTF-8 scan -width 75 last >"$actual"
+run_prog scan -width 75 last >"$actual"
 check "$expected" "$actual"
 
 
-cat >"$expected" <<EOF
-  13  01/13 sender@example.co  ? <<The Subject: is an encoded single quote, 0x9
+if test "$ICONV_ENABLED" -eq 1; then
+  cat >"$expected" <<EOF
+  13  01/13 sender@example.co  <<The Subject: is an encoded single quote, 0x92.
 EOF
 
-cat >"${MH_TEST_DIR}/Mail/inbox/13" <<EOF
+  cat >"${MH_TEST_DIR}/Mail/inbox/13" <<EOF
 From: <sender@example.com>
 Subject: =?iso-8859-1?B?kgo=?=
 Date: Mon, 13 Jan 2014 14:18:33 -0600
@@ -153,8 +154,9 @@ properly count it when decoding, which could be seen with:
 The scan listing was two characters too long.
 EOF
 
-LC_CTYPE=ISO-8859-1 MM_CHARSET=ISO-8859-1 scan -width 80 last >"$actual"
-check "$expected" "$actual"
+  run_prog scan -width 80 last >"$actual"
+  check "$expected" "$actual"
+fi
 
 
 exit $failed
index 3181f21..ba22a19 100755 (executable)
@@ -68,13 +68,13 @@ esac
 # whatnow's exit status is always 1 so that is not a failure
 set +e
 echo "attach $testname_quoted" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
+  run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual
 echo "alist" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
+  run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual
 echo "detach $testname_quoted" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
+  run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual
 echo "alist" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
+  run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual
 set -e
 
 check "$expectederr" "$actualerr"
@@ -84,7 +84,7 @@ if [ "$readline" = 0 ]; then
 cat >"$expected" <<EOF
 whatnow: attach command requires file argument(s).
 whatnow: attach command requires file argument(s).
-#text/plain; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+Attaching ${MH_TEST_DIR}/Mail/context as a text/plain
 EOF
 else
 cat >"$expected" <<EOF
@@ -93,7 +93,7 @@ whatnow: attach command requires file argument(s).
 at -v
 whatnow: attach command requires file argument(s).
 at -v Mail/context
-#text/plain; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+Attaching ${MH_TEST_DIR}/Mail/context as a text/plain
 quit -delete
 EOF
 fi
index e7c865b..534c25d 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -53,7 +53,11 @@ main (int argc, char **argv)
     char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
     struct aka *ak;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index 26706ed..75bcc68 100644 (file)
@@ -94,7 +94,11 @@ main (int argc, char **argv)
     int                list = 0;               /* list header elements if set */
     int                number = 0;             /* delete specific number of like elements if set */
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 88c90f4..ae9df28 100644 (file)
@@ -184,10 +184,7 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
 
     mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
 
-    if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
-    strncpy (tmpfil, cp, sizeof(tmpfil));
+    strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
     chmod (tmpfil, mode);
 
     /*
@@ -415,13 +412,13 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
 
        cpydata (tmpfd, fd, tmpfil, file);
        close (tmpfd);
-       (void) m_unlink (tmpfil);
+       unlink (tmpfil);
     } else {
        strncpy (buffer, m_backup (file), sizeof(buffer));
        if (rename (file, buffer) == NOTOK) {
            switch (errno) {
                case ENOENT:    /* unlinked early - no annotations */
-                   (void) m_unlink (tmpfil);
+                   unlink (tmpfil);
                    break;
 
                default:
index c8cf4b2..a8f9169 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
@@ -53,7 +53,11 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp;
     char **arguments, *addrs[NADDRS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
diff --git a/uip/attach.c b/uip/attach.c
deleted file mode 100644 (file)
index 8be4ed2..0000000
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- * attach.c -- routines to help attach files via whatnow
- *
- * 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 <h/utils.h>
-#include <h/tws.h>
-
-static int get_line(FILE *, char *, size_t);
-#ifdef MIMETYPEPROC
-static char *get_file_info(const char *, const char *);
-#endif /* MIMETYPEPROC */
-
-int
-attach(char *attachment_header_field_name, char *draft_file_name,
-       char *body_file_name, size_t body_file_name_len,
-       char *composition_file_name, size_t composition_file_name_len,
-       int attachformat)
-{
-    char        buf[PATH_MAX + 6];      /* miscellaneous buffer */
-    int         c;                      /* current character for body copy */
-    int         has_attachment;         /* draft has at least one attachment */
-    int         has_body;               /* draft has a message body */
-    int         length;                 /* of attachment header field name */
-    char        *p;                     /* miscellaneous string pointer */
-    struct stat st;                     /* file status buffer */
-    FILE        *body_file = NULL;      /* body file pointer */
-    FILE        *draft_file;            /* draft file pointer */
-    int         field_size;             /* size of header field buffer */
-    char        *field;                 /* header field buffer */
-    FILE        *composition_file;      /* composition file pointer */
-    char        *build_directive;       /* mhbuild directive */
-
-
-    /*
-     * Open up the draft file.
-     */
-
-    if ((draft_file = fopen(draft_file_name, "r")) == (FILE *)0)
-       adios(NULL, "can't open draft file `%s'.", draft_file_name);
-
-    /*
-     *  Allocate a buffer to hold the header components as they're read in.
-     *  This buffer might need to be quite large, so we grow it as needed.
-     */
-
-    field = (char *)mh_xmalloc(field_size = 256);
-
-    /*
-     * Scan the draft file for a header field name, with a non-empty
-     * body, that matches the -attach argument.  The existence of one
-     * indicates that the draft has attachments.  Bail out if there
-     * are no attachments because we're done.  Read to the end of the
-     * headers even if we have no attachments.
-     */
-
-    length = strlen(attachment_header_field_name);
-
-    has_attachment = 0;
-
-    while (get_line(draft_file, field, field_size) != EOF && *field != '\0' &&
-           *field != '-') {
-       if (strncasecmp(field, attachment_header_field_name, length) == 0 &&
-           field[length] == ':') {
-           for (p = field + length + 1; *p == ' ' || *p == '\t'; p++)
-               ;
-           if (strlen (p) > 0) {
-               has_attachment = 1;
-           }
-       }
-    }
-
-    if (has_attachment == 0)
-       return (DONE);
-
-    /*
-     * We have at least one attachment.  Look for at least one non-blank line
-     * in the body of the message which indicates content in the body.
-     */
-
-    has_body = 0;
-
-    while (get_line(draft_file, field, field_size) != EOF) {
-       for (p = field; *p != '\0'; p++) {
-           if (*p != ' ' && *p != '\t') {
-               has_body = 1;
-               break;
-           }
-       }
-
-       if (has_body)
-           break;
-    }
-
-    /*
-     * Make names for the temporary files.
-     */
-
-    if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
-    (void)strncpy(body_file_name, p, body_file_name_len);
-    if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-        (void) m_unlink(body_file_name);
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
-    (void)strncpy(composition_file_name, p, composition_file_name_len);
-
-    if (has_body)
-       body_file = fopen(body_file_name, "w");
-
-    composition_file = fopen(composition_file_name, "w");
-
-    if ((has_body && body_file == (FILE *)0) || composition_file == (FILE *)0) {
-       clean_up_temporary_files(body_file_name, composition_file_name);
-       adios(NULL, "unable to open all of the temporary files.");
-    }
-
-    /*
-     * Start at the beginning of the draft file.  Copy all
-     * non-attachment header fields to the temporary composition
-     * file.  Then add the dashed line separator.
-     */
-
-    rewind(draft_file);
-
-    while (get_line(draft_file, field, field_size) != EOF && *field != '\0' &&
-           *field != '-')
-       if (strncasecmp(field, attachment_header_field_name, length) != 0 ||
-            field[length] != ':')
-           (void)fprintf(composition_file, "%s\n", field);
-
-    (void)fputs("--------\n", composition_file);
-
-    /*
-     * Copy the message body to a temporary file.
-     */
-
-    if (has_body) {
-       while ((c = getc(draft_file)) != EOF)
-               putc(c, body_file);
-
-       (void)fclose(body_file);
-    }
-
-    /*
-     * Add a mhbuild MIME composition file line for the body if there was one.
-     *  Set the default content type to text/plain so that mhbuild takes care
-     *  of any necessary encoding.
-     */
-
-    if (has_body)
-        /*
-         * Make sure that the attachment file exists and is readable.
-         */
-        if (stat(body_file_name, &st) != OK  ||
-            access(body_file_name, R_OK) != OK) {
-            advise(NULL, "unable to access file \"%s\"", body_file_name);
-            return NOTOK;
-        }
-
-    if ((build_directive = construct_build_directive (body_file_name,
-                                                      "text/plain",
-                                                      attachformat)) == NULL) {
-        clean_up_temporary_files(body_file_name, composition_file_name);
-        adios (NULL, "exiting due to failure in attach()");
-    } else {
-        (void) fputs(build_directive, composition_file);
-        free(build_directive);
-    }
-
-    /*
-     * Now, go back to the beginning of the draft file and look for
-     * header fields that specify attachments.  Add a mhbuild MIME
-     * composition file for each.
-     */
-
-    rewind(draft_file);
-
-    while (get_line(draft_file, field, field_size) != EOF && *field != '\0' &&
-           *field != '-') {
-       if (strncasecmp(field, attachment_header_field_name, length) == 0 &&
-            field[length] == ':') {
-           for (p = field + length + 1; *p == ' ' || *p == '\t'; p++)
-               ;
-
-           /* Skip empty attachment_header_field_name lines. */
-           if (strlen (p) > 0) {
-               struct stat st;
-               if (stat(p, &st) == OK  &&  access(p, R_OK) == OK) {
-                   if (S_ISREG (st.st_mode)) {
-                     /* Don't set the default content type so that
-                        construct_build_directive() will try to infer
-                        it from the file type. */
-                        if ((build_directive = construct_build_directive (p, 0,
-                               attachformat)) == NULL) {
-                            clean_up_temporary_files(body_file_name,
-                                                     composition_file_name);
-                            adios (NULL, "exiting due to failure in attach()");
-                        } else {
-                            (void) fputs(build_directive, composition_file);
-                            free(build_directive);
-                        }
-                   } else {
-                       adios (NULL, "unable to attach %s, not a plain file",
-                              p);
-                   }
-               } else {
-                 adios (NULL, "unable to access file \"%s\"", p);
-               }
-           }
-       }
-    }
-
-    (void)fclose(composition_file);
-
-    /*
-     * We're ready to roll!  Run mhbuild on the composition file.
-     * Note that mhbuild is in the context as buildmimeproc.
-     */
-
-    (void)sprintf(buf, "%s %s", buildmimeproc, composition_file_name);
-
-    if (system(buf) != 0) {
-       clean_up_temporary_files(body_file_name, composition_file_name);
-       return NOTOK;
-    }
-
-    return OK;
-}
-
-void
-clean_up_temporary_files(const char *body_file_name,
-                         const char *composition_file_name)
-{
-    (void) m_unlink(body_file_name);
-    (void) m_unlink(composition_file_name);
-
-    return;
-}
-
-static int
-get_line(FILE *draft_file, char *field, size_t field_size)
-{
-    int                c;      /* current character */
-    size_t     n;      /* number of bytes in buffer */
-    char       *p;     /* buffer pointer */
-
-    /*
-     * Get a line from the input file, growing the field buffer as
-     * needed.  We do this so that we can fit an entire line in the
-     * buffer making it easy to do a string comparison on both the
-     * field name and the field body which might be a long path name.
-     */
-
-    for (n = 0, p = field; (c = getc(draft_file)) != EOF; *p++ = c) {
-       if (c == '\n' && (c = getc(draft_file)) != ' ' && c != '\t') {
-           (void)ungetc(c, draft_file);
-           c = '\n';
-           break;
-       }
-
-       if (++n >= field_size - 1) {
-           field = (char *)mh_xrealloc((void *)field, field_size += 256);
-
-           p = field + n - 1;
-       }
-    }
-
-    /*
-     * NUL-terminate the field..
-     */
-
-    *p = '\0';
-
-    return (c);
-}
-
-/*
- * Try to use external command to determine mime type, and possibly
- * encoding.  Caller is responsible for free'ing returned memory.
- */
-char *
-mime_type(const char *file_name) {
-    char *content_type = NULL;  /* mime content type */
-
-#ifdef MIMETYPEPROC
-    char *mimetype;
-
-    if ((mimetype = get_file_info(MIMETYPEPROC, file_name))) {
-#ifdef MIMEENCODINGPROC
-        /* Try to append charset for text content. */
-        char *mimeencoding;
-
-        if (strncasecmp(mimetype, "text", 4) == 0) {
-            if ((mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) {
-                content_type = concat(mimetype, "; charset=", mimeencoding,
-                                      NULL);
-            } else {
-                content_type = strdup(mimetype);
-            }
-        } else {
-            content_type = strdup(mimetype);
-        }
-#else  /* MIMEENCODINGPROC */
-        content_type = strdup(mimetype);
-#endif /* MIMEENCODINGPROC */
-    }
-#else  /* MIMETYPEPROC */
-    NMH_UNUSED(file_name);
-#endif /* MIMETYPEPROC */
-
-    return content_type;
-}
-
-
-#ifdef MIMETYPEPROC
-/*
- * Get information using proc about a file.
- */
-static char *
-get_file_info(const char *proc, const char *file_name) {
-    char *cmd, *cp;
-    char *quotec = "'";
-
-    if ((cp = strchr(file_name, '\''))) {
-        /* file_name contains a single quote. */
-        if (strchr(file_name, '"')) {
-            advise(NULL, "filenames containing both single and double quotes "
-                   "are unsupported for attachment");
-            return NULL;
-        } else {
-            quotec = "\"";
-        }
-    }
-
-    cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
-    if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
-        FILE *fp;
-
-        if ((fp = popen(cmd, "r")) != NULL) {
-            char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
-
-            buf[0] = '\0';
-            if (fgets(buf, sizeof buf, fp)) {
-                char *eol;
-
-                /* Skip leading <filename>:<whitespace>, if present. */
-                if ((cp = strchr(buf, ':')) != NULL) {
-                    ++cp;
-                    while (*cp  &&  isblank((unsigned char) *cp)) {
-                        ++cp;
-                    }
-                } else {
-                    cp = buf;
-                }
-
-                /* Truncate at newline (LF or CR), if present. */
-                if ((eol = strpbrk(cp, "\n\r")) != NULL) {
-                    *eol = '\0';
-                }
-            } else if (buf[0] == '\0') {
-                /* This can happen on Cygwin if the popen()
-                   mysteriously fails.  Return NULL so that the caller
-                   will use another method to determine the info. */
-                free (cp);
-                cp = NULL;
-            }
-
-            (void) pclose(fp);
-        } else {
-            advise(NULL, "no output from %s", cmd);
-        }
-
-        free(cmd);
-    } else {
-        advise(NULL, "concat with \"%s\" failed, out of memory?", proc);
-    }
-
-    return cp  ?  strdup(cp)  :  NULL;
-}
-#endif /* MIMETYPEPROC */
-
-
-/*
- * Construct an mhbuild directive for the draft file.  This starts
- * with the content type.  Append a file name attribute, and depending
- * on attachformat value a private x-unix-mode attribute and a
- * description obtained (if possible) by running the "file" command on
- * the file.  Caller is responsible for free'ing returned memory.
- */
-char *
-construct_build_directive (char *file_name, const char *default_content_type,
-                           int attachformat) {
-    char *build_directive = NULL;  /* Return value. */
-    char *content_type;            /* mime content type */
-    char  cmd[PATH_MAX + 8];       /* file command buffer */
-    struct stat st;                /* file status buffer */
-    char *p;                       /* miscellaneous temporary variables */
-    int   c;                       /* current character */
-
-    if ((content_type = mime_type (file_name)) == NULL) {
-        /*
-         * Check the file name for a suffix.  Scan the context for
-         * that suffix on a mhshow-suffix- entry.  We use these
-         * entries to be compatible with mhnshow, and there's no
-         * reason to make the user specify each suffix twice.  Context
-         * entries of the form "mhshow-suffix-contenttype" in the name
-         * have the suffix in the field, including the dot.
-         */
-        struct node *np;          /* context scan node pointer */
-        static FILE *fp = NULL;   /* pointer for mhn.defaults */
-
-        if (fp == NULL  &&  (fp = fopen (p = etcpath ("mhn.defaults"), "r"))) {
-            readconfig ((struct node **) NULL, fp, p, 0);
-            fclose(fp);
-        }
-
-        if ((p = strrchr(file_name, '.')) != NULL) {
-            for (np = m_defs; np; np = np->n_next) {
-                if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 &&
-                    strcasecmp(p, np->n_field ? np->n_field : "") == 0) {
-                    content_type = strdup (np->n_name + 14);
-                    break;
-                }
-            }
-        }
-
-        if (content_type == NULL  &&  default_content_type != NULL) {
-            content_type = strdup (default_content_type);
-        }
-    }
-
-    /*
-     * No content type was found, either because there was no matching
-     * entry in the context or because the file name has no suffix.
-     * Open the file and check for non-ASCII characters.  Choose the
-     * content type based on this check.
-     */
-    if (content_type == NULL) {
-        int  binary; /* binary character found flag */
-        FILE *fp;
-
-        if ((fp = fopen(file_name, "r")) == (FILE *)0) {
-            advise(NULL, "unable to access file \"%s\"", file_name);
-            return NULL;
-        }
-
-        binary = 0;
-
-        while ((c = getc(fp)) != EOF) {
-            if (c > 127 || c < 0) {
-                binary = 1;
-                break;
-            }
-        }
-
-        (void) fclose(fp);
-
-        content_type =
-            strdup (binary ? "application/octet-stream" : "text/plain");
-    }
-
-    switch (attachformat) {
-    case 0: {
-        struct stat st;
-        FILE *fp;
-        char m[4];
-
-        /* Insert name, file mode, and Content-Id. */
-        if (stat(file_name, &st) != OK  ||  access(file_name, R_OK) != OK) {
-            advise(NULL, "unable to access file \"%s\"", file_name);
-            return NULL;
-        }
-
-        snprintf (m, sizeof m, "%.3ho", (unsigned short)(st.st_mode & 0777));
-        build_directive = concat ("#", content_type, "; name=\"",
-                                  ((p = strrchr(file_name, '/')) == NULL)
-                                  ?  file_name
-                                  :  p + 1,
-                                  "\"; x-unix-mode=0", m, NULL);
-
-        if (strlen(file_name) > PATH_MAX) {
-            advise(NULL, "attachment file name `%s' too long.", file_name);
-            return NULL;
-        }
-
-        (void) sprintf(cmd, "file '%s'", file_name);
-
-        if ((fp = popen(cmd, "r")) != NULL  &&
-            fgets(cmd, sizeof (cmd), fp) != NULL) {
-            *strchr(cmd, '\n') = '\0';
-
-            /*
-             *  The output of the "file" command is of the form
-             *
-             *          file: description
-             *
-             *  Strip off the "file:" and subsequent white space.
-             */
-            for (p = cmd; *p != '\0'; p++) {
-                if (*p == ':') {
-                    for (p++; *p != '\0'; p++) {
-                        if (*p != '\t')
-                            break;
-                    }
-                    break;
-                }
-            }
-
-            if (*p != '\0') {
-                /* Insert Content-Description. */
-                build_directive =
-                    concat (build_directive, " [ ", p, " ]", NULL);
-            }
-
-            (void) pclose(fp);
-        }
-        break;
-    }
-    case 1:
-        if (stringdex (m_maildir(invo_name), file_name) == 0) {
-            /* Content had been placed by send into a temp file.
-               Don't generate Content-Disposition header, because
-               it confuses Microsoft Outlook, Build 10.0.6626, at
-               least. */
-            build_directive = concat ("#", content_type, " <>", NULL);
-        } else {
-            /* Suppress Content-Id, insert simple Content-Disposition
-               and Content-Description with filename.
-               The Content-Disposition type needs to be "inline" for
-               MS Outlook and BlackBerry calendar programs to properly
-               handle a text/calendar attachment. */
-            p = strrchr(file_name, '/');
-            build_directive = concat ("#", content_type, "; name=\"",
-                                      (p == NULL) ? file_name : p + 1,
-                                      "\" <> [",
-                                      (p == NULL) ? file_name : p + 1,
-                                      "]{",
-                                      strcmp ("text/calendar", content_type)
-                                        ? "attachment" : "inline",
-                                      "}", NULL);
-        }
-
-        break;
-    case 2:
-        if (stringdex (m_maildir(invo_name), file_name) == 0) {
-            /* Content had been placed by send into a temp file.
-               Don't generate Content-Disposition header, because
-               it confuses Microsoft Outlook, Build 10.0.6626, at
-               least. */
-            build_directive = concat ("#", content_type, " <>", NULL);
-        } else {
-            /* Suppress Content-Id, insert Content-Disposition with
-               modification date and Content-Description wtih filename.
-               The Content-Disposition type needs to be "inline" for
-               MS Outlook and BlackBerry calendar programs to properly
-               handle a text/calendar attachment. */
-
-            if (stat(file_name, &st) != OK  ||  access(file_name, R_OK) != OK) {
-                advise(NULL, "unable to access file \"%s\"", file_name);
-                return NULL;
-            }
-
-            p = strrchr(file_name, '/');
-            build_directive = concat ("#", content_type, "; name=\"",
-                                      (p == NULL) ? file_name : p + 1,
-                                      "\" <> [",
-                                      (p == NULL) ? file_name : p + 1,
-                                      "]{",
-                                      strcmp ("text/calendar", content_type)
-                                        ? "attachment" : "inline",
-                                      "; modification-date=\"",
-                                      dtime (&st.st_mtime, 0),
-                                      "}", NULL);
-        }
-
-        break;
-    default:
-        advise (NULL, "unsupported attachformat %d", attachformat);
-    }
-
-    free(content_type);
-
-    /*
-     * Finish up with the file name.
-     */
-    build_directive = concat (build_directive, " ", file_name, "\n", NULL);
-
-    return build_directive;
-}
index ff5af23..e838422 100644 (file)
@@ -75,7 +75,11 @@ main (int argc, char **argv)
     struct smsg *smsgs;
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -458,14 +462,8 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 
     i = inplace ? msgnum + numburst : mp->hghmsg;
     for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
-        char *tempfile;
-
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       strncpy (f2, tempfile, sizeof(f2));
        strncpy (f1, m_name (i), sizeof(f1));
+       strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2));
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
index 02feefa..a7300c3 100644 (file)
@@ -83,7 +83,11 @@ main (int argc, char **argv)
     struct format *fmt;
     struct stat st;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 4c14002..9174a39 100644 (file)
@@ -68,7 +68,12 @@ main (int argc, char **argv)
     char *cp, **argp, **arguments;
     char buf[BUFSIZ], *akv[50];
 
-    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* foil search of user profile/context */
+    if (context_foil (NULL) == -1)
+       done (1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
index 5a35e59..00503be 100644 (file)
@@ -83,7 +83,11 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     struct stat st;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 2d9239e..d7a2712 100644 (file)
@@ -87,7 +87,7 @@ distout (char *drft, char *msgnam, char *backup)
        leave_bad: ;
                fclose (ifp);
                fclose (ofp);
-               (void) m_unlink (drft);
+               unlink (drft);
                if (rename (backup, drft) == NOTOK)
                    adios (drft, "unable to rename %s to", backup);
                return NOTOK;
@@ -104,7 +104,7 @@ process: ;
     if (!resent) {
        advise (NULL, BADMSG, "draft");
        fclose (ofp);
-       (void) m_unlink (drft);
+       unlink (drft);
        if (rename (backup, drft) == NOTOK)
            adios (drft, "unable to rename %s to", backup);
        return NOTOK;
@@ -141,13 +141,14 @@ ready_msg (char *msgnam)
 
     cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
     if (cp == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+        adios("distsbr", "unable to create temporary file");
     }
+    fchmod(hdrfd, 0600);
     strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
 
     for (;;) {
        int buffersz = sizeof buffer;
@@ -169,15 +170,14 @@ ready_msg (char *msgnam)
 
                 cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
                 if (cp == NULL) {
-                   adios(NULL, "unable to create temporary file in %s",
-                         get_temp_dir());
+                    adios("distsbr", "unable to create temporary file");
                 }
                 fchmod(txtfd, 0600);
                strncpy (tmpfil, cp, sizeof(tmpfil));
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");
-               (void) m_unlink (tmpfil);
+               unlink (tmpfil);
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
                    buffersz = sizeof buffer;
index dabdd74..8245f60 100644 (file)
--- a/uip/dp.c
+++ b/uip/dp.c
@@ -51,7 +51,11 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp, **arguments;
     char *dates[NDATES];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index da2752d..2cf5b59 100644 (file)
@@ -567,7 +567,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start,
        clear = 1;
 
     if (!clear && map_chk (file, fd, &d1, pos, noisy)) {
-       (void) m_unlink (file);
+       unlink (file);
        mbx_close (file, fd);
        if ((fd = map_open (file, md)) == NOTOK)
            return NOTOK;
index 829500d..cea1ca7 100644 (file)
@@ -115,7 +115,11 @@ main(int argc, char **argv)
     char **arguments;
     char buf[BUFSIZ];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex(argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     /*
      * If program was invoked with name ending
index f1df6f3..289f1e6 100644 (file)
@@ -51,7 +51,11 @@ main (int argc, char **argv)
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 2f45e7b..a3a436f 100644 (file)
@@ -121,7 +121,11 @@ main (int argc, char **argv)
     int dat[5];
     struct fmt_callbacks cb, *cbp = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 98ecde6..a2e6a4a 100644 (file)
@@ -101,7 +101,11 @@ main (int argc, char **argv)
     char *cp, *dp, *msg = NULL, *argfolder = NULL;
     char **ap, **argp, buf[BUFSIZ], **arguments;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     /*
      * If program was invoked with name ending
index 2139d35..9eeb612 100644 (file)
@@ -116,9 +116,14 @@ main (int argc, char **argv)
     char **argp, **arguments;
     struct stat st;
     struct msgs_array msgs = { 0, 0, NULL };
+
     int buildsw = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 295507d..48fecb1 100644 (file)
@@ -174,11 +174,9 @@ finished:
     }
 
     cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
-    if (cp == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    if (cp == NULL) adios("forw", "unable to create temporary file");
     strncpy (tmpfil, cp, sizeof(tmpfil));
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");
 
index b76f1cd..3aa5e50 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -197,7 +197,11 @@ main (int argc, char **argv)
     SAVEGROUPPRIVS();
     TRYDROPGROUPPRIVS();
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -656,7 +660,7 @@ go_to_it:
            } else {
                if (ferror(pf) || fclose (pf)) {
                    int e = errno;
-                   (void) m_unlink (cp);
+                   unlink (cp);
                    pop_quit ();
                    errno = e;
                    adios (cp, "write error on");
@@ -751,7 +755,7 @@ go_to_it:
                        break;
                if (ferror(sf) || fflush(pf) || ferror(pf)) {
                        int e = errno;
-                       fclose(pf); fclose(sf); (void) m_unlink(cp);
+                       fclose(pf); fclose(sf); unlink(cp);
                        errno = e;
                        adios(cp, "copy error %s -> %s", sp, cp);
                }
@@ -798,14 +802,14 @@ go_to_it:
            }
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
-               (void) m_unlink (cp);
+               unlink (cp);
                errno = e;
                adios (cp, "write error on");
            }
            pf = NULL;
            free (cp);
 
-           if (trnflag && m_unlink (sp) == NOTOK)
+           if (trnflag && unlink (sp) == NOTOK)
                adios (sp, "couldn't unlink");
            free (sp); /* Free Maildir[i]->filename */
        }
@@ -847,7 +851,7 @@ go_to_it:
                    close (newfd);
                else
                    admonish (newmail, "error zero'ing");
-               (void) m_unlink(map_name(newmail));
+               unlink(map_name(newmail));
            }
        } else {
            if (noisy)
index 1237735..0fc97c4 100644 (file)
@@ -42,8 +42,8 @@ main (int argc, char **argv)
     FILE *in, *out;
     int                check;
 
-    if (nmh_init(argv[0], 0 /* use context_foil() */ )) { return 1; }
-
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
 
index da25f0b..439ea40 100644 (file)
@@ -52,7 +52,11 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 1a16071..85b5a21 100644 (file)
@@ -44,6 +44,7 @@
     X("version", 0, VERSIONSW) \
     X("help", 0, HELPSW) \
     X("debug", -5, DEBUGSW) \
+    X("dist", -4, DISTSW) \
 
 #define X(sw, minchars, id) id,
 DEFINE_SWITCH_ENUM(MHBUILD);
@@ -65,6 +66,9 @@ DEFINE_SWITCH_ENUM(MIMEENCODING);
 DEFINE_SWITCH_ARRAY(MIMEENCODING, encodingswitches);
 #undef X
 
+/* mhbuildsbr.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -100,7 +104,7 @@ int list_all_messages (CT *, int, int, int, int);
 int
 main (int argc, char **argv)
 {
-    int sizesw = 1, headsw = 1, directives = 1, autobuild = 0;
+    int sizesw = 1, headsw = 1, directives = 1, autobuild = 0, dist = 0;
     int *icachesw;
     char *cp, buf[BUFSIZ];
     char buffer[BUFSIZ], *compfile = NULL;
@@ -110,10 +114,14 @@ main (int argc, char **argv)
     FILE *fp_out = NULL;
     int header_encoding = CE_UNKNOWN;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=unlink_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -261,6 +269,9 @@ main (int argc, char **argv)
            case DEBUGSW:
                debugsw = 1;
                continue;
+           case DISTSW:
+               dist = 1;
+               continue;
            }
        }
        if (compfile)
@@ -298,6 +309,16 @@ main (int argc, char **argv)
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
+    /*
+     * Check for storage directory.  If defined, we
+     * will store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
@@ -309,20 +330,15 @@ main (int argc, char **argv)
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
-       if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-
        /* copy standard input to temporary file */
-       strncpy (infile, cp, sizeof(infile));
+       strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
        unlink_infile = 1;
 
        /* build the content structures for MIME message */
-       ct = build_mime (infile, autobuild, directives, header_encoding);
+       ct = build_mime (infile, autobuild, dist, directives, header_encoding);
 
        /*
         * If ct == NULL, that means that -auto was set and a MIME version
@@ -341,7 +357,7 @@ main (int argc, char **argv)
            free_content (ct);
        }
 
-       (void) m_unlink (infile);
+       unlink (infile);
        unlink_infile = 0;
 
        done (0);
@@ -352,7 +368,7 @@ main (int argc, char **argv)
      */
 
     /* build the content structures for MIME message */
-    ct = build_mime (compfile, autobuild, directives, header_encoding);
+    ct = build_mime (compfile, autobuild, dist, directives, header_encoding);
 
     /*
      * If ct == NULL, that means -auto was set and we found a MIME version
@@ -366,10 +382,8 @@ main (int argc, char **argv)
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
-    if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
-    strncpy(outfile, cp, sizeof(outfile));
+    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
+            sizeof(outfile));
     unlink_outfile = 1;
 
     /* output the message */
@@ -410,9 +424,9 @@ unlink_done (int status)
      * temporary files.
      */
     if (unlink_infile)
-       (void) m_unlink (infile);
+       unlink (infile);
     if (unlink_outfile)
-       (void) m_unlink (outfile);
+       unlink (outfile);
 
     exit (status);
 }
index 2b78a36..e590922 100644 (file)
@@ -42,6 +42,12 @@ extern int contentidsw;
 extern int rcachesw;   /* mhcachesbr.c */
 extern int wcachesw;   /* mhcachesbr.c */
 
+/*
+ * Directory to place tmp files.  This must
+ * be set before these routines are called.
+ */
+char *tmp;
+
 pid_t xpid = 0;
 
 static char prefix[] = "----- =_aaaaaaaaaa";
@@ -74,7 +80,7 @@ void free_encoding (CT, int);
 static int init_decoded_content (CT);
 static void setup_attach_content(CT, char *);
 static char *fgetstr (char *, int, FILE *);
-static int user_content (FILE *, char *, char *, CT *);
+static int user_content (FILE *, char *, CT *);
 static void set_id (CT, int);
 static int compose_content (CT);
 static int scan_content (CT);
@@ -123,7 +129,8 @@ static void directive_pop(void)
  */
 
 CT
-build_mime (char *infile, int autobuild, int directives, int header_encoding)
+build_mime (char *infile, int autobuild, int dist, int directives,
+           int header_encoding)
 {
     int        compnum, state;
     char buf[BUFSIZ], name[NAMESZ];
@@ -230,7 +237,9 @@ build_mime (char *infile, int autobuild, int directives, int header_encoding)
 
                entry = mh_xmalloc(sizeof(*entry));
                entry->filename = getcpy(s);
+               entry->next = NULL;
                free(vp);
+
                if (attach_tail) {
                    attach_tail->next = entry;
                    attach_tail = entry;
@@ -277,9 +286,12 @@ finish_field:
      * Now add the MIME-Version header field
      * to the list of header fields.
      */
-    np = add (VRSN_FIELD, NULL);
-    vp = concat (" ", VRSN_VALUE, "\n", NULL);
-    add_header (ct, np, vp);
+
+    if (! dist) {
+       np = add (VRSN_FIELD, NULL);
+       vp = concat (" ", VRSN_VALUE, "\n", NULL);
+       add_header (ct, np, vp);
+    }
 
     /*
      * We initally assume we will find multiple contents in the
@@ -305,7 +317,7 @@ finish_field:
        struct part *part;
        CT p;
 
-       if (user_content (in, infile, buf, &p) == DONE) {
+       if (user_content (in, buf, &p) == DONE) {
            admonish (NULL, "ignoring spurious #end");
            continue;
        }
@@ -319,12 +331,6 @@ finish_field:
        part->mp_part = p;
     }
 
-    /*
-     * close the composition draft since
-     * it's not needed any longer.
-     */
-    fclose (in);
-
     /*
      * Add any Attach headers to the list of MIME parts at the end of the
      * message.
@@ -363,9 +369,55 @@ finish_field:
        free(at_prev);
     }
 
-    /* check if any contents were found */
-    if (!m->mp_parts)
-       adios (NULL, "no content directives found");
+    /*
+     * To allow for empty message bodies, if we've found NO content at all
+     * yet cook up an empty text/plain part.
+     */
+
+    if (!m->mp_parts) {
+       CT p;
+       struct part *part;
+       struct text *t;
+
+       if ((p = (CT) calloc (1, sizeof(*p))) == NULL)
+           adios(NULL, "out of memory");
+
+       init_decoded_content(p);
+
+       if (get_ctinfo ("text/plain", p, 0) == NOTOK)
+           done (1);
+
+       p->c_type = CT_TEXT;
+       p->c_subtype = TEXT_PLAIN;
+       p->c_encoding = CE_7BIT;
+       p->c_file = getcpy(infile);
+       /*
+        * Sigh.  ce_file contains the "decoded" contents of this part.
+        * So this seems like the best option available since we're going
+        * to call scan_content() on this.
+        */
+       p->c_cefile.ce_file = getcpy("/dev/null");
+       p->c_begin = ftell(in);
+       p->c_end = ftell(in);
+
+       if ((t = (struct text *) calloc (1, sizeof (*t))) == NULL)
+           adios (NULL, "out of memory");
+
+       t->tx_charset = CHARSET_SPECIFIED;
+       p->c_ctparams = t;
+
+       if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
+           adios (NULL, "out of memory");
+       *pp = part;
+       pp = &part->mp_next;
+       part->mp_part = p;
+    }
+
+    /*
+     * close the composition draft since
+     * it's not needed any longer.
+     */
+    fclose (in);
 
     /*
      * If only one content was found, then remove and
@@ -415,7 +467,8 @@ finish_field:
     }
 
     /* Build the rest of the header field structures */
-    build_headers (ct);
+    if (! dist)
+       build_headers (ct);
 
     return ct;
 }
@@ -481,7 +534,7 @@ fgetstr (char *s, int n, FILE *stream)
  */
 
 static int
-user_content (FILE *in, char *file, char *buf, CT *ctp)
+user_content (FILE *in, char *buf, CT *ctp)
 {
     int        extrnal, vrsn;
     char *cp, **ap;
@@ -527,10 +580,8 @@ user_content (FILE *in, char *file, char *buf, CT *ctp)
        FILE *out;
         char *cp;
 
-       if ((cp = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
-           adios("mhbuildsbr", "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
+        cp = m_mktemp2(NULL, invo_name, NULL, &out);
+        if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
 
        /* use a temp file to collect the plain text lines */
        ce->ce_file = add (cp, NULL);
@@ -950,7 +1001,7 @@ use_forw:
            struct part *part;
            CT p;
 
-           if (user_content (in, file, buffer, &p) == DONE) {
+           if (user_content (in, buffer, &p) == DONE) {
                if (!m->mp_parts)
                    adios (NULL, "empty \"#begin ... #end\" sequence");
                return OK;
@@ -1089,10 +1140,10 @@ compose_content (CT ct)
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
-           if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-               adios("mhbuildsbr", "unable to create temporary file in %s",
-                     get_temp_dir());
-           }
+            tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+            if (tfile == NULL) {
+                adios("mhbuildsbr", "unable to create temporary file");
+            }
            ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
index 136b567..0bf725c 100644 (file)
@@ -143,11 +143,11 @@ cache_content (CT ct)
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
-               (void) m_unlink (cachefile);
+               unlink (cachefile);
            } else {
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
-                   (void) m_unlink (cachefile);
+                   unlink (cachefile);
                }
            }
            fclose (fp);
@@ -273,7 +273,7 @@ got_it:
     if (status == OK && writing) {
        if (*writing && strchr(buffer, '/'))
            make_intermediates (buffer);
-       (void) m_unlink (buffer);
+       unlink (buffer);
     }
 
     free (id);
index 2016250..bafd78e 100644 (file)
@@ -53,6 +53,7 @@ int debugsw; /* Needed by mhparse.c. */
 #define quitser pipeser
 
 /* mhparse.c */
+extern char *tmp;                             /* directory to place tmp files */
 extern int skip_mp_cte_check;                 /* flag to InitMultiPart */
 extern int suppress_bogus_mp_content_warning; /* flag to InitMultiPart */
 extern int bogus_mp_content;                  /* flag from InitMultiPart */
@@ -134,10 +135,14 @@ main (int argc, char **argv) {
     fx.decodetext = CE_8BIT;
     fx.textcodeset = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done = freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -259,6 +264,16 @@ main (int argc, char **argv) {
         fclose (fp);
     }
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+        tmp = concat (cp, "/", invo_name, NULL);
+    else
+        tmp = add (m_maildir (invo_name), NULL);
+
     suppress_bogus_mp_content_warning = skip_mp_cte_check = 1;
 
     if (! context_find ("path"))
@@ -283,17 +298,17 @@ main (int argc, char **argv) {
 
             using_stdin = 1;
 
-            if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
-                adios (NULL, "unable to create temporary file in %s",
-                       get_temp_dir());
+            if ((cp = m_mktemp2 (tmp, invo_name, &fd, NULL)) == NULL) {
+                adios (NULL, "unable to create temporary file");
             } else {
                 free (file);
                 file = add (cp, NULL);
+                chmod (file, 0600);
                 cpydata (STDIN_FILENO, fd, "-", file);
             }
 
             if (close (fd)) {
-                (void) m_unlink (file);
+                unlink (file);
                 adios (NULL, "failed to write temporary file");
             }
         }
@@ -356,7 +371,7 @@ main (int argc, char **argv) {
             status += mhfixmsgsbr (ctp, &fx, outfile);
 
             if (using_stdin) {
-                (void) m_unlink (file);
+                unlink (file);
 
                 if (! outfile) {
                     /* Just calling m_backup() unlinks the backup file. */
@@ -369,6 +384,7 @@ main (int argc, char **argv) {
     }
 
     free (outfile);
+    free (tmp);
     free (file);
 
     /* done is freects_done, which will clean up all of cts. */
@@ -390,12 +406,7 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
         modify_inplace = 1;
 
         if ((*ctp)->c_file) {
-            char *tempfile;
-            if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
-                adios (NULL, "unable to create temporary file in %s",
-                       get_temp_dir());
-            }
-            outfile = add (tempfile, NULL);
+            outfile = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
         } else {
             adios (NULL, "missing both input and output filenames\n");
         }
@@ -457,7 +468,7 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
     }
 
     if (modify_inplace) {
-        if (status != OK) (void) m_unlink (outfile);
+        if (status != OK) unlink (outfile);
         free (outfile);
         outfile = NULL;
     }
@@ -513,7 +524,7 @@ fix_boundary (CT *ct, int *message_mods) {
             if (get_multipart_boundary (*ct, &part_boundary) == OK) {
                 char *fixed;
 
-                if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) {
+                if ((fixed = m_mktemp2 (tmp, invo_name, NULL, &(*ct)->c_fp))) {
                     if (replace_boundary (*ct, fixed, part_boundary) == OK) {
                         char *filename = add ((*ct)->c_file, NULL);
 
@@ -533,8 +544,7 @@ fix_boundary (CT *ct, int *message_mods) {
                         status = NOTOK;
                     }
                 } else {
-                    advise (NULL, "unable to create temporary file in %s",
-                            get_temp_dir());
+                    advise (NULL, "unable to create temporary file");
                     status = NOTOK;
                 }
 
@@ -1019,13 +1029,7 @@ build_text_plain_part (CT encoded_part) {
            contains the decoded contents.  And the decoding function, such
            as openQuoted, will have set ...->ce_unlink to 1 so that it will
            be unlinked by free_content (). */
-        char *tempfile;
-
-        if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
-            advise (NULL, "unable to create temporary file in %s",
-                    get_temp_dir());
-        }
-        tmp_plain_file = add (tempfile, NULL);
+        tmp_plain_file = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
         if (reformat_part (tp_part, tmp_plain_file,
                            tp_part->c_ctinfo.ci_type,
                            tp_part->c_ctinfo.ci_subtype,
@@ -1035,7 +1039,7 @@ build_text_plain_part (CT encoded_part) {
     }
 
     free_content (tp_part);
-    (void) m_unlink (tmp_plain_file);
+    unlink (tmp_plain_file);
     free (tmp_plain_file);
 
     return NULL;
@@ -1096,17 +1100,13 @@ static int
 decode_part (CT ct) {
     char *tmp_decoded;
     int status;
-    char *tempfile;
 
-    if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
-        adios (NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
-    tmp_decoded = add (tempfile, NULL);
+    tmp_decoded = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
     /* The following call will load ct->c_cefile.ce_file with the tmp
        filename of the decoded content.  tmp_decoded will contain the
        encoded output, get rid of that. */
     status = output_message (ct, tmp_decoded);
-    (void) m_unlink (tmp_decoded);
+    unlink (tmp_decoded);
     free (tmp_decoded);
 
     return status;
@@ -1166,7 +1166,7 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) {
     /* Unlink decoded content tmp file and free its filename to avoid
        leaks.  The file stream should already have been closed. */
     if (ct->c_cefile.ce_unlink) {
-        (void) m_unlink (ct->c_cefile.ce_file);
+        unlink (ct->c_cefile.ce_file);
         free (ct->c_cefile.ce_file);
         ct->c_cefile.ce_file = NULL;
         ct->c_cefile.ce_unlink = 0;
@@ -1486,7 +1486,7 @@ decode_text_parts (CT ct, int encoding, int *message_mods) {
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
-                    (void) m_unlink (ct->c_cefile.ce_file);
+                    unlink (ct->c_cefile.ce_file);
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else if (ct->c_encoding == CE_QUOTED  &&
@@ -1500,7 +1500,7 @@ decode_text_parts (CT ct, int encoding, int *message_mods) {
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
-                    (void) m_unlink (ct->c_cefile.ce_file);
+                    unlink (ct->c_cefile.ce_file);
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else {
@@ -1689,14 +1689,8 @@ strip_crs (CT ct, int *message_mods) {
 
             if (has_crs) {
                 int fd;
-                char *stripped_content_file;
-                char *tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL); 
-
-                if (tempfile == NULL) {
-                    adios (NULL, "unable to create temporary file in %s",
-                           get_temp_dir());
-                }
-                stripped_content_file = add (tempfile, NULL);
+                char *stripped_content_file =
+                    add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
 
                 /* Strip each CR before a LF from the content. */
                 fseeko (*fp, begin, SEEK_SET);
@@ -1723,13 +1717,13 @@ strip_crs (CT ct, int *message_mods) {
                 if (close (fd)) {
                     admonish (NULL, "unable to write temporary file %s",
                               stripped_content_file);
-                    (void) m_unlink (stripped_content_file);
+                    unlink (stripped_content_file);
                     status = NOTOK;
                 } else {
                     /* Replace the decoded file with the converted one. */
                     if (ct->c_cefile.ce_file) {
                         if (ct->c_cefile.ce_unlink) {
-                            (void) m_unlink (ct->c_cefile.ce_file);
+                            unlink (ct->c_cefile.ce_file);
                         }
                         free (ct->c_cefile.ce_file);
                     }
@@ -1848,7 +1842,6 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
         HF hf;
-        char *tempfile;
 
         if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
             (iconv_t) -1) {
@@ -1856,11 +1849,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
             return -1;
         }
 
-        if ((tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
-            adios (NULL, "unable to create temporary file in %s",
-                   get_temp_dir());
-        }
-        dest = add (tempfile, NULL);
+        dest = add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
 
         if (ct->c_cefile.ce_file) {
             file = &ct->c_cefile.ce_file;
@@ -1923,7 +1912,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
             /* Replace the decoded file with the converted one. */
             if (ct->c_cefile.ce_file) {
                 if (ct->c_cefile.ce_unlink) {
-                    (void) m_unlink (ct->c_cefile.ce_file);
+                    unlink (ct->c_cefile.ce_file);
                 }
                 free (ct->c_cefile.ce_file);
             }
@@ -1962,7 +1951,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
                 }
             }
         } else {
-            (void) m_unlink (dest);
+            unlink (dest);
         }
 #else  /* ! HAVE_ICONV */
         NMH_UNUSED (message_mods);
@@ -2012,7 +2001,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
                         }
                         if (new != -1) close (new);
                         if (old != -1) close (old);
-                        (void) m_unlink (outfile);
+                        unlink (outfile);
 
                         if (i < 0) {
                             /* The -file argument processing used path() to
@@ -2028,7 +2017,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
                 } else {
                     admonish (NULL, "unable to remove input file %s, "
                               "not modifying it", infile);
-                    (void) m_unlink (outfile);
+                    unlink (outfile);
                     status = NOTOK;
                 }
 
@@ -2038,7 +2027,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
             }
         } else {
             /* No modifications and didn't need the tmp outfile. */
-            (void) m_unlink (outfile);
+            unlink (outfile);
         }
     } else {
         /* Output is going to some file.  Produce it whether or not
index 2975687..5fa2a59 100644 (file)
@@ -106,7 +106,7 @@ free_content (CT ct)
 
     if (ct->c_file) {
        if (ct->c_unlink)
-           (void) m_unlink (ct->c_file);
+           unlink (ct->c_file);
        free (ct->c_file);
     }
     if (ct->c_fp)
@@ -270,7 +270,7 @@ free_encoding (CT ct, int toplevel)
 
     if (ce->ce_file) {
        if (ce->ce_unlink)
-           (void) m_unlink (ce->ce_file);
+           unlink (ce->ce_file);
        free (ce->ce_file);
        ce->ce_file = NULL;
     }
index 652fb11..d4c5308 100644 (file)
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -13,8 +13,7 @@
 int
 main (int argc, char **argv)
 {
-    if (nmh_init(argv[0], 1)) { return 1; }
-
+    setlocale(LC_ALL, "");
     done (mhl (argc, argv));
     return 1;
 }
index f37041c..7092434 100644 (file)
@@ -47,6 +47,9 @@ DEFINE_SWITCH_ARRAY(MHLIST, switches);
 #undef X
 
 
+/* mhparse.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -104,10 +107,14 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -236,6 +243,16 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index f4df180..6a1c3db 100644 (file)
@@ -349,6 +349,11 @@ mhl (int argc, char **argv)
     char buf[BUFSIZ], *files[MAXARGS];
     char **argp, **arguments;
 
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
index 916732d..a0baf2e 100755 (executable)
@@ -84,8 +84,7 @@ fi
 tolist=                     ## To: addresses
 toarg=0                     ## whether currently handling -to
 attacharg=0                 ## whether currently handling -attach
-attach_send_switch_added=0  ## whether added "-attach Nmh-Attachment" switch
-attachind=Nmh-Attachment    ## attachment indicator
+attachind=Attach            ## attachment indicator
 body=                       ## contents of the message body
 bodyarg=0                   ## whether currently handling -body
 cclist=                     ## Cc: addresses
@@ -114,11 +113,7 @@ for arg in "$@"; do
        mhmailswitch=1
        attacharg=1
        use_send=1
-       if [ $attach_send_switch_added -eq 0 ]; then
-         #### Override any send -attach switch in user's profile.
-         postsendargs="${postsendargs:+$postsendargs }-attach $attachind"
-         attach_send_switch_added=1
-       fi ;;
+       ;;
     -b|-bo|-bod|-body) mhmailswitch=1; bodyarg=1 ;;
     -c|-cc) mhmailswitch=1; ccarg=1 ;;
     -f|-fr|-fro|-from) mhmailswitch=1; fromarg=1 ;;
index 08405d4..06aeee5 100644 (file)
--- a/uip/mhn.c
+++ b/uip/mhn.c
@@ -77,6 +77,9 @@ DEFINE_SWITCH_ARRAY(MHN, switches);
 #undef X
 
 
+/* mhparse.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -164,10 +167,14 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -404,6 +411,16 @@ do_cache:
      */
     cwd = getcpy (pwd());
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index 8a276f7..b0c119c 100644 (file)
@@ -131,7 +131,10 @@ main(int argc, char **argv)
     char *cp, buf[BUFSIZ], **argp;
     char **arguments, *comps[MAXARGS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 716a22f..5e35cbb 100644 (file)
@@ -28,6 +28,12 @@ extern int wcachesw; /* mhcachesbr.c */
 
 int checksw = 0;       /* check Content-MD5 field */
 
+/*
+ * Directory to place temp files.  This must
+ * be set before these routines are called.
+ */
+char *tmp;
+
 /*
  * These are for mhfixmsg to:
  * 1) Instruct parser not to detect invalid Content-Transfer-Encoding
@@ -194,23 +200,23 @@ parse_mime (char *file)
     if ((is_stdin = !(strcmp (file, "-")))) {
         char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
         if (tfile == NULL) {
-            advise("mhparse", "unable to create temporary file in %s",
-                  get_temp_dir());
+            advise("mhparse", "unable to create temporary file");
             return NULL;
         }
        file = add (tfile, NULL);
+       chmod (file, 0600);
 
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
        fflush (fp);
 
        if (ferror (stdin)) {
-           (void) m_unlink (file);
+           unlink (file);
            advise ("stdin", "error reading");
            return NULL;
        }
        if (ferror (fp)) {
-           (void) m_unlink (file);
+           unlink (file);
            advise (file, "error writing");
            return NULL;
        }
@@ -222,7 +228,7 @@ parse_mime (char *file)
 
     if (!(ct = get_content (fp, file, 1))) {
        if (is_stdin)
-           (void) m_unlink (file);
+           unlink (file);
        advise (NULL, "unable to decode %s", file);
        return NULL;
     }
@@ -1646,12 +1652,7 @@ openBase64 (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1669,7 +1670,17 @@ openBase64 (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
+        if (ce->ce_unlink) {
+            /* Temporary file already exists, so we rename to
+               version with extension. */
+            char *file_org = strdup(ce->ce_file);
+            ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -1875,12 +1886,7 @@ openQuoted (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1898,7 +1904,17 @@ openQuoted (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
+        if (ce->ce_unlink) {
+            /* Temporary file already exists, so we rename to
+               version with extension. */
+            char *file_org = strdup(ce->ce_file);
+            ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -2094,12 +2110,7 @@ open7Bit (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2117,7 +2128,17 @@ open7Bit (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (! ce->ce_unlink) {
+        if (ce->ce_unlink) {
+            /* Temporary file already exists, so we rename to
+               version with extension. */
+            char *file_org = strdup(ce->ce_file);
+            ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -2340,12 +2361,12 @@ openFile (CT ct, char **file)
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
-               (void) m_unlink (cachefile);
+               unlink (cachefile);
            }
            else
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
-                   (void) m_unlink (cachefile);
+                   unlink (cachefile);
                }
            fclose (fp);
        }
@@ -2478,14 +2499,8 @@ openFTP (CT ct, char **file)
        ce->ce_file = add (*file, NULL);
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
-    else {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
-    }
+    else
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2556,12 +2571,12 @@ openFTP (CT ct, char **file)
 
                if (ferror (gp)) {
                    admonish (ce->ce_file, "error reading");
-                   (void) m_unlink (cachefile);
+                   unlink (cachefile);
                }
                else
                    if (ferror (fp)) {
                        admonish (cachefile, "error writing");
-                       (void) m_unlink (cachefile);
+                       unlink (cachefile);
                    }
                fclose (fp);
            }
@@ -2673,12 +2688,7 @@ openMail (CT ct, char **file)
     }
 
     if (*file == NULL) {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2771,14 +2781,8 @@ openURL (CT ct, char **file)
        ce->ce_file = add(*file, NULL);
     else if (caching)
        ce->ce_file = add(cachefile, NULL);
-    else {
-       char *tempfile;
-       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       ce->ce_file = add (tempfile, NULL);
-    }
+    else
+       ce->ce_file = add(m_mktemp(tmp, NULL, NULL), NULL);
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
        content_error(ce->ce_file, ct, "unable to fopen for read/writing");
@@ -2831,7 +2835,7 @@ openURL (CT ct, char **file)
 
                if (ferror(gp)) {
                    admonish(ce->ce_file, "error reading");
-                   (void) m_unlink (cachefile);
+                   unlink(cachefile);
                }
            }
            umask(mask);
index b9506d7..29b59f4 100644 (file)
@@ -32,7 +32,11 @@ main(int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index f83236b..f19f9a9 100644 (file)
@@ -56,6 +56,9 @@ DEFINE_SWITCH_ARRAY(MHSHOW, switches);
 #undef X
 
 
+/* mhparse.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -114,10 +117,14 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -284,6 +291,16 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index fb5349f..fff480a 100644 (file)
@@ -48,6 +48,9 @@ DEFINE_SWITCH_ARRAY(MHSTORE, switches);
 int save_clobber_policy (const char *);
 extern int files_not_clobbered;
 
+/* mhparse.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -103,10 +106,14 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -260,6 +267,16 @@ do_cache:
      */
     cwd = getcpy (pwd());
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index 7b1dbd5..93d3e90 100644 (file)
@@ -562,10 +562,7 @@ store_content (CT ct, CT p)
            char *tmpfilenam, *folder;
 
            /* Store content in temporary file for now */
-           if ((tmpfilenam = m_mktemp(invo_name, NULL, NULL)) == NULL) {
-               adios(NULL, "unable to create temporary file in %s",
-                     get_temp_dir());
-           }
+           tmpfilenam = m_mktemp(invo_name, NULL, NULL);
            ct->c_storage = add (tmpfilenam, NULL);
 
            /* Get the folder name */
@@ -626,7 +623,7 @@ got_filename:
      */
     if (ct->c_folder && (!is_partial || last_partial)) {
        msgnum = output_content_folder (ct->c_folder, ct->c_storage);
-       (void) m_unlink (ct->c_storage);
+       unlink (ct->c_storage);
        if (msgnum == NOTOK)
            return NOTOK;
     }
index b85a91e..092b542 100644 (file)
@@ -42,6 +42,9 @@ DEFINE_SWITCH_ARRAY(MHTEST, switches);
 #undef X
 
 
+/* mhparse.c */
+extern char *tmp;      /* directory to place temp files */
+
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -99,10 +102,14 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=freects_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -219,6 +226,16 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
+    /*
+     * Check for storage directory.  If specified,
+     * then store temporary files there.  Else we
+     * store them in standard nmh directory.
+     */
+    if ((cp = context_find (nmhstorage)) && *cp)
+       tmp = concat (cp, "/", invo_name, NULL);
+    else
+       tmp = add (m_maildir (invo_name), NULL);
+
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
@@ -343,6 +360,7 @@ static void
 pipeser (int i)
 {
     if (i == SIGQUIT) {
+       unlink ("core");
        fflush (stdout);
        fprintf (stderr, "\n");
        fflush (stderr);
index 49e758f..39a2918 100644 (file)
@@ -85,7 +85,11 @@ main (int argc, char **argv)
     char **argp, **arguments, *vec[MAXVEC];
     struct passwd *pw;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
 
index e91924c..75371ba 100644 (file)
--- a/uip/msh.c
+++ b/uip/msh.c
@@ -203,7 +203,11 @@ main (int argc, char **argv)
     char *cp, *file = NULL, *folder = NULL;
     char **argp, **arguments, buf[BUFSIZ];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc,argv, 1);
@@ -1114,7 +1118,7 @@ quit (void)
                close (i);
            else
                advise (mp->foldpath, "error zero'ing");
-           (void) m_unlink (map_name (mp->foldpath));/* XXX */
+           unlink (map_name (mp->foldpath));/* XXX */
        }
        goto release;
     }
@@ -1131,8 +1135,8 @@ quit (void)
     for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
        if (does_exist(mp, msgnum) && pack (tmpfil, md, msgnum) == NOTOK) {
            mbx_close (tmpfil, md);
-           (void) m_unlink (tmpfil);
-           (void) m_unlink (map_name (tmpfil));
+           unlink (tmpfil);
+           unlink (map_name (tmpfil));
            goto release;
        }
     mbx_close (tmpfil, md);
@@ -1145,8 +1149,8 @@ quit (void)
 
        if (rename (map1, map2) == NOTOK) {
            admonish (map2, "unable to rename %s to", map1);
-           (void) m_unlink (map1);
-           (void) m_unlink (map2);
+           unlink (map1);
+           unlink (map2);
        }
     }
 
index 6627c6a..3a5f98f 100644 (file)
@@ -1011,7 +1011,7 @@ forw (char *proc, char *filter, int vecp, char **vec)
                break;
        }
 
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
 }
 
 
@@ -2842,7 +2842,7 @@ ready: ;
     }
 
     if (!fmsh)
-       (void) m_unlink (tmpfil);
+       unlink (tmpfil);
     return status;
 }
 
index 6f99825..59b5b8c 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -422,7 +422,11 @@ main(int argc, char **argv)
     char *unseen;
     struct node *folder;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex(argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 30f0f48..6f95191 100644 (file)
@@ -46,10 +46,14 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=mbxclose_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
index 740f6f0..a915920 100644 (file)
@@ -66,10 +66,14 @@ main (int argc, char **argv)
     struct msgs *mp, *mp2;
     register FILE *fp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=putzero_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
index 9b35852..f6e14fb 100644 (file)
@@ -283,7 +283,12 @@ main (int argc, char **argv)
     FILE *in, *out;
     m_getfld_state_t gstate = 0;
 
-    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* foil search of user profile/context */
+    if (context_foil (NULL) == -1)
+       done (1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
@@ -528,12 +533,15 @@ main (int argc, char **argv)
            if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
-           char *cp = m_mktemp2(NULL, invo_name, NULL, &out);
-           if (cp == NULL) {
-               adios(NULL, "unable to create temporary file in %s",
-                     get_temp_dir());
-           }
+            char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
+            if (cp == NULL) {
+                cp = m_mktemp2(NULL, invo_name, NULL, &out);
+                if (cp == NULL) {
+                   adios ("post", "unable to create temporary file");
+                }
+            }
             strncpy(tmpfil, cp, sizeof(tmpfil));
+           chmod (tmpfil, 0600);
        }
     }
 
@@ -630,13 +638,13 @@ main (int argc, char **argv)
            post (tmpfil, 0, verbose, envelope);
        }
        post (bccfil, 1, verbose, envelope);
-       (void) m_unlink (bccfil);
+       unlink (bccfil);
     } else {
        post (tmpfil, 0, isatty (1), envelope);
     }
 
     p_refile (tmpfil);
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
 
     if (verbose) {
        if (partno)
@@ -1272,9 +1280,8 @@ make_bcc_file (int dashstuff)
     FILE *out;
     char *tfile = NULL, *program;
 
-    if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    tfile = m_mktemp2(NULL, "bccs", NULL, &out);
+    if (tfile == NULL) adios("bcc", "unable to create temporary file");
     strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "From: %s\n", fullfrom);
@@ -1705,9 +1712,9 @@ sigser (int i)
 {
     NMH_UNUSED (i);
 
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
     if (msgflags & MINV)
-       (void) m_unlink (bccfil);
+       unlink (bccfil);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
@@ -1829,9 +1836,9 @@ die (char *what, char *fmt, ...)
 {
     va_list ap;
 
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
     if (msgflags & MINV)
-       (void) m_unlink (bccfil);
+       unlink (bccfil);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
index 37f5960..7923e84 100644 (file)
@@ -78,7 +78,11 @@ main (int argc, char **argv)
     char *tmpfil;
     m_getfld_state_t gstate = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -148,9 +152,9 @@ main (int argc, char **argv)
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
-    if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    tmpfil = m_mktemp2(NULL, invo_name, NULL, &out);
+    if (tmpfil == NULL) adios("prompter", "unable to create temporary file");
+    chmod (tmpfil, 0600);
 
     /*
      * Are we changing the kill or erase character?
@@ -227,7 +231,7 @@ abort:
                        if (killp || erasep) {
                            tcsetattr(0, TCSADRAIN, &tio);
                        }
-                       (void) m_unlink (tmpfil);
+                       unlink (tmpfil);
                        done (1);
                    }
                    if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
@@ -316,7 +320,7 @@ abort:
     cpydata (fdi, fdo, tmpfil, drft);
     close (fdi);
     close (fdo);
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
 
     context_save ();   /* save the context file */
     done (0);
index 85baf33..8b672cd 100644 (file)
@@ -48,10 +48,14 @@ main (int argc, char **argv)
     FILE *fp;
     char *tfile = NULL;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=unlink_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     /*
      * Configure this now, since any unknown switches to rcvdist get
      * sent to postproc
@@ -98,17 +102,15 @@ main (int argc, char **argv)
 
     umask (~m_gmprot ());
 
-    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+    if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
-    if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+    if (tfile == NULL) adios("forw", "unable to create temporary file");
     strncpy (drft, tfile, sizeof(tmpfil));
 
     rcvdistout (fp, form, addrs);
@@ -253,11 +255,11 @@ static void
 unlink_done (int status)
 {
     if (backup[0])
-       (void) m_unlink (backup);
+       unlink (backup);
     if (drft[0])
-       (void) m_unlink (drft);
+       unlink (drft);
     if (tmpfil[0])
-       (void) m_unlink (tmpfil);
+       unlink (tmpfil);
 
     exit (status ? RCV_MBX : RCV_MOK);
 }
index bbd0e08..08e21b9 100644 (file)
@@ -40,7 +40,11 @@ main (int argc, char **argv)
     char *cp, *file = NULL, buf[BUFSIZ];
     char **argp, **arguments;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index be0ac39..98f1750 100644 (file)
@@ -54,10 +54,14 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
-
     done=unlink_done;
 
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -158,7 +162,7 @@ main (int argc, char **argv)
     /* create a temporary file */
     tmpfilenam = m_mktemp (invo_name, &fd, NULL);
     if (tmpfilenam == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+       adios ("rcvstore", "unable to create temporary file");
     }
     chmod (tmpfilenam, m_gmprot());
 
@@ -166,7 +170,7 @@ main (int argc, char **argv)
     cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
 
     if (fstat (fd, &st) == NOTOK) {
-       (void) m_unlink (tmpfilenam);
+       unlink (tmpfilenam);
        adios (tmpfilenam, "unable to fstat");
     }
     if (close (fd) == NOTOK)
@@ -174,7 +178,7 @@ main (int argc, char **argv)
 
     /* don't add file if it is empty */
     if (st.st_size == 0) {
-       (void) m_unlink (tmpfilenam);
+       unlink (tmpfilenam);
        advise (NULL, "empty file");
        done (0);
     }
@@ -212,7 +216,7 @@ main (int argc, char **argv)
     folder_free (mp);          /* free folder/message structure          */
 
     context_save ();           /* save the global context file           */
-    (void) m_unlink (tmpfilenam); /* remove temporary file                  */
+    unlink (tmpfilenam);       /* remove temporary file                  */
     tmpfilenam = NULL;
 
     done (0);
@@ -226,6 +230,6 @@ static void
 unlink_done(int status)
 {
     if (tmpfilenam && *tmpfilenam)
-       (void) m_unlink (tmpfilenam);
+       unlink (tmpfilenam);
     exit (status);
 }
index 3bee075..447c6e4 100644 (file)
@@ -82,7 +82,11 @@ main (int argc, char **argv)
     char **argp, **arguments, *vec[MAXARGS];
     struct utmpx *utp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -184,15 +188,13 @@ message_fd (char **vec)
 {
     pid_t child_id;
     int bytes, seconds;
-    int fd;
-    char *tfile;
+    /* volatile to prevent "might be clobbered" warning from gcc: */
+    volatile int fd;
+    char tmpfil[BUFSIZ];
     struct stat st;
 
-    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
-       advise(NULL, "unable to create temporary file in %s", get_temp_dir());
-       return NOTOK;
-    }
-    (void) m_unlink(tfile);  /* Use fd, no longer need the file name. */
+    fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)));
+    unlink (tmpfil);
 
     if ((child_id = fork()) == NOTOK) {
        /* fork error */
@@ -252,11 +254,9 @@ header_fd (void)
     char *nfs;
     char *tfile = NULL;
 
-    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
-       advise(NULL, "unable to create temporary file in %s", get_temp_dir());
-        return NOTOK;
-    }
-    (void) m_unlink(tfile);  /* Use fd, no longer need the file name. */
+    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+    if (tfile == NULL) return NOTOK;
+    unlink (tfile);
 
     rewind (stdin);
 
index ecbe346..776c6fd 100644 (file)
@@ -68,7 +68,11 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -338,7 +342,7 @@ remove_files (int filep, char **files)
     /* Else just unlink the files */
     files++;   /* advance past filevec[0] */
     for (i = 0; i < filep; i++) {
-       if (m_unlink (files[i]) == NOTOK)
+       if (unlink (files[i]) == NOTOK)
            admonish (files[i], "unable to unlink");
     }
 }
index 7b0ab4a..d1c8ebf 100644 (file)
@@ -129,7 +129,11 @@ main (int argc, char **argv)
 
     int buildsw = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index bb03805..735cf77 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -37,7 +37,11 @@ main (int argc, char **argv)
     char *cp, *folder = NULL, newfolder[BUFSIZ];
     char buf[BUFSIZ], **argp, **arguments;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -179,7 +183,7 @@ rmf (char *folder)
                others++;
                continue;
        }
-       if (m_unlink (dp->d_name) == NOTOK) {
+       if (unlink (dp->d_name) == NOTOK) {
            admonish (dp->d_name, "unable to unlink %s:", folder);
            others++;
        }
index 8644a02..8882b8f 100644 (file)
--- a/uip/rmm.c
+++ b/uip/rmm.c
@@ -37,7 +37,11 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 2066869..3130922 100644 (file)
@@ -52,7 +52,11 @@ main (int argc, char **argv)
     struct msgs *mp;
     FILE *in;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index 9d6e207..626eba1 100644 (file)
@@ -62,8 +62,8 @@
     X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
     X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
     X("user username", SASLminc(-4), USERSW) \
-    X("attach", 6, ATTACHSW) \
-    X("noattach", 0, NOATTACHSW) \
+    X("attach", -6, ATTACHSW) \
+    X("noattach", -8, NOATTACHSW) \
     X("attachformat", 7, ATTACHFORMATSW) \
     X("port server-port-name/number", 4, PORTSW) \
     X("tls", TLSminc(-3), TLSSW) \
@@ -117,10 +117,12 @@ main (int argc, char **argv)
     char *msgs[MAXARGS], **vec;
     struct msgs *mp;
     struct stat st;
-    char *attach = NMH_ATTACH_HEADER;  /* header field name for attachments */
-    int attachformat = 1; /* mhbuild format specifier for attachments */
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -267,26 +269,14 @@ main (int argc, char **argv)
                    continue;
                
                case ATTACHSW:
-                   if (!(attach = *argp++) || *attach == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                   advise(NULL, "The -attach switch is deprecated");
                    continue;
                case NOATTACHSW:
-                   attach = NULL;
+                   advise(NULL, "The -noattach switch is deprecated");
                    continue;
 
                case ATTACHFORMATSW:
-                   if (! *argp || **argp == '-')
-                       adios (NULL, "missing argument to %s", argp[-1]);
-                   else {
-                       attachformat = atoi (*argp);
-                       if (attachformat < 0 ||
-                           attachformat > ATTACHFORMATS - 1) {
-                           advise (NULL, "unsupported attachformat %d",
-                                   attachformat);
-                           continue;
-                       }
-                   }
-                   ++argp;
+                   advise(NULL, "The -attachformat switch is deprecated");
                    continue;
            }
        } else {
@@ -392,12 +382,8 @@ go_to_it:
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
-       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       distfile = getcpy (cp);
-       (void) m_unlink(distfile);
+       distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
+       unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
            /* Cygwin with FAT32 filesystem produces EPERM. */
            if (errno != EXDEV  &&  errno != EPERM
@@ -407,11 +393,7 @@ go_to_it:
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
-           if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
-               adios(NULL, "unable to create temporary file in %s",
-                     get_temp_dir());
-           }
-           distfile = getcpy (cp);
+           distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
            {
                int in, out;
                struct stat st;
@@ -442,8 +424,7 @@ go_to_it:
     closefds (3);
 
     for (msgnum = 0; msgnum < msgp; msgnum++) {
-       switch (sendsbr (vec, vecp, program, msgs[msgnum], &st, 1, attach,
-                        attachformat)) {
+       switch (sendsbr (vec, vecp, program, msgs[msgnum], &st, 1)) {
            case DONE: 
                done (++status);
            case NOTOK: 
index a7dc38a..aa4426e 100644 (file)
@@ -14,6 +14,7 @@
 #include <h/mime.h>
 #include <h/tws.h>
 #include <h/utils.h>
+#include <h/mts.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -34,12 +35,6 @@ char *distfile = NULL;
 
 static jmp_buf env;
 
-/*
- * external prototypes
- */
-int sendsbr (char **, int, char *, char *, struct stat *, int, char *, int);
-char *getusername (void);
-
 /*
  * static prototypes
  */
@@ -57,48 +52,43 @@ static int sendaux (char **, int, char *, char *, struct stat *);
  */
 
 int
-sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st,
-         int rename_drft, char *attachment_header_field_name, int attachformat)
+sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
+         int rename_drft)
 {
-    int status;
+    int status, i;
+    pid_t child;
     char buffer[BUFSIZ], file[BUFSIZ];
     struct stat sts;
-    char       *original_draft;                /* name of original draft file */
-    char       *p;                             /* string pointer for building file name */
-    char       composition_file_name[PATH_MAX + 1]; /* name of mhbuild composition temporary file */
-    char       body_file_name[PATH_MAX + 1];   /* name of temporary file for body content */
-
-    /*
-     * Save the original name of the draft file.  The name of the draft file is changed
-     * to a temporary file containing the built MIME message if there are attachments.
-     * We need the original name so that it can be renamed after the message is sent.
-     */
-
-    original_draft = drft;
+    char **buildvec, *buildprogram;
+    char *volatile drft = draft;
 
     /*
-     * There might be attachments if a header field name for attachments is supplied.
-     * Convert the draft to a MIME message.  Use the mhbuild composition file for the
-     * draft if there was a successful conversion because that now contains the MIME
-     * message.  A nice side effect of this is that it leaves the original draft file
-     * untouched so that it can be retrieved and modified if desired.
+     * Run the mimebuildproc (which is by default mhbuild) on the message
+     * with the addition of the "-auto" flag
      */
 
-    if (attachment_header_field_name != (char *)0) {
-       switch (attach(attachment_header_field_name, drft,
-                       body_file_name, sizeof body_file_name,
-                       composition_file_name, sizeof composition_file_name,
-                       attachformat)) {
-       case OK:
-           drft = composition_file_name;
-           break;
+    switch (child = fork()) {
+    case NOTOK:
+       adios("fork", "unable to");
+       break;
 
-       case NOTOK:
-           return (NOTOK);
+    case OK:
+       buildvec = argsplit(buildmimeproc, &buildprogram, &i);
+       buildvec[i++] = "-auto";
+       if (distfile)
+           buildvec[i++] = "-dist";
+       buildvec[i++] = (char *) drft;
+       buildvec[i] = NULL;
+       execvp(buildprogram, buildvec);
+       fprintf(stderr, "unable to exec ");
+       perror(buildmimeproc);
+       _exit(-1);
+       break;
 
-       case DONE:
-           break;
-       }
+    default:
+       if (pidXwait(child, buildmimeproc))
+           return NOTOK;
+       break;
     }
 
     done=armed_done;
@@ -109,11 +99,10 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st,
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
-           char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
-           if (cp == NULL) {
-               adios(NULL, "unable to create temporary file in %s",
-                     get_temp_dir());
-           }
+            char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+            if (cp == NULL) {
+                adios ("sendsbr", "unable to create temporary file");
+            }
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
@@ -123,16 +112,18 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st,
         * Check if we need to split the message into
         * multiple messages of type "message/partial".
         */
-       if (splitsw >= 0 && !distfile && stat (drft, &sts) != NOTOK
+       if (splitsw >= 0 && !distfile && stat ((char *) drft, &sts) != NOTOK
                && sts.st_size >= CPERMSG) {
-           status = splitmsg (vec, vecp, program, drft, st, splitsw) ? NOTOK : OK;
+           status = splitmsg (vec, vecp, program, drft,
+                              st, splitsw) ? NOTOK : OK;
        } else {
            status = sendaux (vec, vecp, program, drft, st) ? NOTOK : OK;
        }
 
        /* rename the original draft */
        if (rename_drft && status == OK &&
-               rename (original_draft, strncpy (buffer, m_backup (original_draft), sizeof(buffer))) == NOTOK)
+               rename (drft, strncpy (buffer, m_backup (drft),
+                                sizeof(buffer))) == NOTOK)
            advise (buffer, "unable to rename %s to", drft);
        break;
 
@@ -143,34 +134,7 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st,
 
     done=exit;
     if (distfile)
-       (void) m_unlink (distfile);
-
-    /*
-     * Get rid of any temporary files that we created for attachments.  Also get rid of
-     * the renamed composition file that mhbuild leaves as a turd.  It looks confusing,
-     * but we use the body file name to help build the renamed composition file name.
-     */
-
-    if (drft == composition_file_name) {
-       clean_up_temporary_files(body_file_name, composition_file_name);
-
-       if (strlen(composition_file_name) >= sizeof (composition_file_name) - 6)
-           advise((char *)0, "unable to remove original composition file.");
-
-       else {
-           if ((p = strrchr(composition_file_name, '/')) == (char *)0)
-               p = composition_file_name;
-           else
-               p++;
-           
-           (void)strcpy(body_file_name, p);
-           *p++ = ',';
-           (void)strcpy(p, body_file_name);
-           (void)strcat(p, ".orig");
-           
-           (void)m_unlink(composition_file_name);
-       }
-    }
+       unlink (distfile);
 
     return status;
 }
@@ -322,10 +286,10 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
+           adios (drft, "unable to create temporary file for");
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
+       chmod (tmpdrf, 0600);
 
        /*
         * Output the header fields
@@ -389,7 +353,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        snprintf (partnum, sizeof(partnum), "%d", partno);
        status = sendaux (vec, vecp, program, tmpdrf, st);
-       (void) m_unlink (tmpdrf);
+       unlink (tmpdrf);
        if (status != OK)
            break;
 
@@ -431,8 +395,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
            snprintf (buf, sizeof(buf), "%d", fd2);
            vec[vecp++] = buf;
        } else {
-           admonish (NULL, "unable to create temporary file in %s "
-                      "for annotation list", get_temp_dir());
+           admonish (NULL, "unable to create file for annotation list");
        }
     }
     if (distfile && distout (drft, distfile, backup) == NOTOK)
@@ -487,7 +450,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
            if (annotext && fd2 != NOTOK)
                close (fd2);
            if (distfile) {
-               (void) m_unlink (drft);
+               unlink (drft);
                if (rename (backup, drft) == NOTOK)
                    advise (drft, "unable to rename %s to", backup);
            }
@@ -573,14 +536,16 @@ static int
 tmp_fd (void)
 {
     int fd;
-    char *tfile;
+    char *tfile = NULL;
 
-    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK;
+    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+    if (tfile == NULL) return NOTOK;
+    fchmod(fd, 0600);
 
     if (debugsw)
        advise (NULL, "temporary file %s selected", tfile);
     else
-       if (m_unlink (tfile) == NOTOK)
+       if (unlink (tfile) == NOTOK)
            advise (tfile, "unable to remove");
 
     return fd;
@@ -623,8 +588,6 @@ anno (int fd, struct stat *st)
            sigaddset (&set, SIGTERM);
            sigprocmask (SIG_BLOCK, &set, &oset);
 
-           unregister_for_removal(0);
-
            annoaux (fd);
            if (child_id == OK)
                _exit (0);
index acd08af..14d4191 100644 (file)
@@ -61,7 +61,11 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs_array vec = { 0, 0, NULL };
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
index eaa7cb7..8dace05 100644 (file)
@@ -188,7 +188,12 @@ main (int argc, char **argv)
     char mailbox[BUFSIZ], tmpfil[BUFSIZ];
     char **argp, **arguments;
 
-    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (*argv, '/');
+
+    /* foil search of user profile/context */
+    if (context_foil (NULL) == -1)
+       done (1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
@@ -310,16 +315,14 @@ main (int argc, char **argv)
        if (debug)
            debug_printf ("retrieving message from file \"%s\"\n", file);
        if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
-           adios(NULL, "unable to create temporary file in %s",
-                  get_temp_dir());
+           adios (NULL, "unable to create temporary file");
        close (tempfd);
     } else {
        /* getting message from stdin */
        if (debug)
            debug_printf ("retrieving message from stdin\n");
        if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
-           adios(NULL, "unable to create temporary file in %s",
-                  get_temp_dir());
+           adios (NULL, "unable to create temporary file");
     }
 
     if (debug)
@@ -336,7 +339,7 @@ main (int argc, char **argv)
        thing would be to delay this unlink() until later if debug == 1, but I'll
        leave that for someone who cares about the temp-file-accessing
        functionality (they'll have to watch out for cases where we adios()). */
-    (void) m_unlink (tmpfil);
+    unlink (tmpfil);
 
     if (!(fp = fdopen (fd, "r+")))
        adios (NULL, "unable to access temporary file");
@@ -1193,6 +1196,7 @@ copy_message (int qd, char *tmpfil, int fold)
 
     tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
     if (tfile == NULL) return -1;
+    fchmod(fd1, 0600);
     strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
@@ -1200,7 +1204,7 @@ copy_message (int qd, char *tmpfil, int fold)
            if (write (fd1, buffer, i) != i) {
 you_lose:
                close (fd1);
-               (void) m_unlink (tmpfil);
+               unlink (tmpfil);
                return -1;
            }
        if (i == -1)
index 3df1885..f6a66f1 100644 (file)
@@ -78,7 +78,11 @@ main (int argc, char **argv)
     struct smsg **dlist;
     int checksw = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 6bce740..1344738 100644 (file)
@@ -54,11 +54,13 @@ main (int argc, char **argv)
     int delay = 0;
     char *f1 = NULL, *f2 = NULL, *f3 = NULL;
     char *f4 = NULL, *f5 = NULL, *f7 = NULL;
-    static char postpath[PATH_MAX];
     char *cp, buf[BUFSIZ];
     char **argp, **arguments;
 
-    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
@@ -133,34 +135,6 @@ main (int argc, char **argv)
     if (!f1)
        adios (NULL, "missing -viamail \"mailpath\" switch");
 
-    /* viamail doesn't read the context and postproc isn't always what
-       we want, such as when running make distcheck.  If we have the
-       absolute path, set postproc to point to post in the same
-       directory as this executable.
-       This could be generalized to handle relative paths (by
-       converting to absolute), to find the full path from PATH given
-       just the basename, and to squash out ../ but it's only needed
-       here.  viamail is typically called from sendfiles, which
-       provides the absolute path.
-     */
-    if (argv[0]  &&  argv[0][0] == '/'  &&
-           strlen(argv[0]) - 3 < sizeof postpath) {
-       strncpy (postpath, argv[0], sizeof postpath - 1);
-       postpath[sizeof postpath - 1] = '\0';
-       if ((cp = strrchr (postpath, '/'))) {
-           struct stat st;
-
-           *(cp + 1) = '\0';
-           /* strlen ("post") <= sizeof postpath - (cp - postpath) - 2
-              but use strncat just in case the code above changes. */
-           strncat (postpath, "post", sizeof postpath - (cp - postpath) - 2);
-
-           if (stat (postpath, &st) == OK) {
-               postproc = postpath;
-           }
-       }
-    }
-
     via_mail (f1, f2, f3, f4, f5, delay, f7);
     return 0;  /* dead code to satisfy the compiler */
 }
@@ -184,9 +158,9 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
 
     umask (~m_gmprot ());
 
-    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
-       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
-    }
+    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+    if (tfile == NULL) adios("viamail", "unable to create temporary file");
+    chmod(tfile, 0600);
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
@@ -243,7 +217,7 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
        vec[vecp++] = cp;
     }
 
-    switch (sendsbr (vec, vecp, program, tmpfil, &st, 0, (char *)0, 0)) {
+    switch (sendsbr (vec, vecp, program, tmpfil, &st, 0)) {
        case DONE:
        case NOTOK:
            status++;
@@ -253,8 +227,8 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
     }
 
     fclose (fp);
-    if (m_unlink (tmpfil) == -1)
-       advise (tmpfil, "unable to remove temp file %s", tmpfil);
+    if (unlink (tmpfil) == -1)
+       advise (NULL, "unable to remove temp file %s", tmpfil);
     done (status);
     return 1;
 }
index 031ff3c..4950514 100644 (file)
@@ -13,7 +13,6 @@
 int
 main (int argc, char **argv)
 {
-    if (nmh_init(argv[0], 1)) { return 1; }
-
+    setlocale(LC_ALL, "");
     return WhatNow (argc, argv);
 }
index 7f5c6c3..005095a 100644 (file)
@@ -53,8 +53,9 @@
     X("prompt string", 4, PRMPTSW) \
     X("version", 0, VERSIONSW) \
     X("help", 0, HELPSW) \
-    X("attach header-field-name", 0, ATTACHSW) \
-    X("noattach", 0, NOATTACHSW) \
+    X("attach header-field-name", -6, ATTACHSW) \
+    X("noattach", -8, NOATTACHSW) \
+
 
 #define X(sw, minchars, id) id,
 DEFINE_SWITCH_ENUM(WHATNOW);
@@ -103,7 +104,6 @@ static int editfile (char **, char **, char *, int, struct msgs *,
 static int sendfile (char **, char *, int);
 static void sendit (char *, char **, char *, int);
 static int buildfile (char **, char *);
-static int check_draft (char *);
 static int whomfile (char **, char *);
 static int removefile (char *);
 static void writelscmd(char *, int, char *, char **);
@@ -122,7 +122,6 @@ WhatNow (int argc, char **argv)
     char buf[BUFSIZ], prompt[BUFSIZ];
     char **argp, **arguments;
     struct stat st;
-    char       *attach = NMH_ATTACH_HEADER;/* attachment header field name */
     char       cwd[PATH_MAX + 1];      /* current working directory */
     char       file[PATH_MAX + 1];     /* file name buffer */
     char       shell[PATH_MAX + 1];    /* shell response buffer */
@@ -130,6 +129,11 @@ WhatNow (int argc, char **argv)
     char       *l;                     /* set on -l to alist  command */
     int                n;                      /* set on -n to alist command */
 
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
+
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -192,12 +196,11 @@ WhatNow (int argc, char **argv)
                continue;
 
            case ATTACHSW:
-               if (!(attach = *argp++) || *attach == '-')
-                   adios (NULL, "missing argument to %s", argp[-2]);
+               advise(NULL, "The -attach switch is deprecated");
                continue;
 
            case NOATTACHSW:
-               attach = NULL;
+               advise(NULL, "The -noattach switch is deprecated");
                continue;
            }
        }
@@ -235,7 +238,7 @@ WhatNow (int argc, char **argv)
 #else /* ! READLINE_SUPPORT */
        if (!(argp = getans (prompt, aleqs))) {
 #endif /* READLINE_SUPPORT */
-           (void) m_unlink (LINK);
+           unlink (LINK);
            done (1);
        }
        switch (smatch (*argp, aleqs)) {
@@ -355,11 +358,6 @@ WhatNow (int argc, char **argv)
             *   -n     numbers listing
             */
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't list because no header field name was given.");
-               break;
-           }
-
            l = (char *)0;
            n = 0;
 
@@ -385,7 +383,7 @@ WhatNow (int argc, char **argv)
                advise((char *)0, "usage is alist [-ln].");
 
            else
-               annolist(drft, attach, l, n);
+               annolist(drft, ATTACH_FIELD, l, n);
 
            break;
 
@@ -397,11 +395,6 @@ WhatNow (int argc, char **argv)
             int verbose = 0;
             char **ap;
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't attach because no header field name was given.");
-               break;
-           }
-
            for (ap = argp+1; *ap; ++ap) {
                if (strcmp(*ap, "-v") == 0) {
                    ++argp;
@@ -432,28 +425,25 @@ WhatNow (int argc, char **argv)
 
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
-                   char *build_directive;
+                   char *ctype;
 
                    *(strchr(shell, '\n')) = '\0';
 
                    if (*shell == '/') {
-                       (void)annotate(drft, attach, shell, 1, 0, -2, 1);
-                       if (verbose) {
-                           build_directive =
-                               construct_build_directive (shell, NULL, 1);
-                       }
+                       strncpy(file, shell, sizeof(file));
+                       file[sizeof(file) - 1] = '\0';
                    } else {
-                       (void)sprintf(file, "%s/%s", cwd, shell);
-                       (void)annotate(drft, attach, file, 1, 0, -2, 1);
-                       if (verbose) {
-                           build_directive =
-                               construct_build_directive (file, NULL, 1);
-                       }
+                       snprintf(file, sizeof(file), "%s/%s", cwd, shell);
                    }
 
+                   annotate(drft, ATTACH_FIELD, file, 1, 0, -2, 1);
                    if (verbose) {
-                       printf ("%s", build_directive);
-                       free (build_directive);
+                       ctype = mime_type(file);
+                   }
+
+                   if (verbose) {
+                       printf ("Attaching %s as a %s\n", file, ctype);
+                       free (ctype);
                    }
                }
 
@@ -470,11 +460,6 @@ WhatNow (int argc, char **argv)
             *  Detach files from current draft.
             */
 
-           if (attach == (char *)0) {
-               advise((char *)0, "can't detach because no header field name was given.");
-               break;
-           }
-
            /*
             *  Scan the arguments for a -n.  Mixed file names and numbers aren't allowed,
             *  so this catches a -n anywhere in the argument list.
@@ -501,7 +486,7 @@ WhatNow (int argc, char **argv)
 
                    if (**arguments != '\0') {
                        n = atoi(*arguments);
-                       (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
+                       annotate(drft, ATTACH_FIELD, (char *)0, 1, 0, n, 1);
 
                        for (argp = arguments + 1; *argp != (char *)0; argp++) {
                            if (atoi(*argp) > n) {
@@ -528,7 +513,7 @@ WhatNow (int argc, char **argv)
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
                    *(strchr(shell, '\n')) = '\0';
-                   (void)annotate(drft, attach, shell, 1, 0, 0, 1);
+                   annotate(drft, ATTACH_FIELD, shell, 1, 0, 0, 1);
                }
                pclose(f);
            } else {
@@ -696,7 +681,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
            snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
 
        if (atfile) {
-           (void) m_unlink (linkpath);
+           unlink (linkpath);
            if (link (altpath, linkpath) == NOTOK) {
                symlink (altpath, linkpath);
                slinked = 1;
@@ -762,7 +747,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
                                && copyf (linkpath, altpath) == NOTOK
                           : stat (linkpath, &st) != NOTOK
                                && st.st_nlink == 1
-                               && (m_unlink (altpath) == NOTOK
+                               && (unlink (altpath) == NOTOK
                                        || link (linkpath, altpath) == NOTOK)))
                advise (linkpath, "unable to update %s from", altmsg);
     }
@@ -773,7 +758,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
 
     *ed = NULL;
     if (altmsg && atfile)
-       (void) m_unlink (linkpath);
+       unlink (linkpath);
 
     return status;
 }
@@ -817,19 +802,6 @@ sendfile (char **arg, char *file, int pushsw)
     int i, vecp;
     char *cp, *sp, **vec, *program;
 
-    /* Translate MIME composition file, if necessary */
-    if ((cp = context_find ("automimeproc"))
-           && (!strcmp (cp, "1"))
-           && check_draft (file)
-           && (buildfile (NULL, file) == NOTOK))
-       return 0;
-
-    /* For backwards compatibility */
-    if ((cp = context_find ("automhnproc"))
-           && check_draft (file)
-           && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0, 0)))
-       return 0;
-
     /*
      * If the sendproc is the nmh command `send', then we call
      * those routines directly rather than exec'ing the command.
@@ -912,66 +884,6 @@ buildfile (char **argp, char *file)
 }
 
 
-/*
- *  Check if draft is a mhbuild composition file
- */
-
-static int
-check_draft (char *msgnam)
-{
-    int        state;
-    char buf[BUFSIZ], name[NAMESZ];
-    FILE *fp;
-    m_getfld_state_t gstate = 0;
-
-    if ((fp = fopen (msgnam, "r")) == NULL)
-       return 0;
-    for (;;) {
-       int bufsz = sizeof buf;
-       switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) {
-           case FLD:
-           case FLDPLUS:
-               /*
-                * If draft already contains any of the
-                * Content-XXX fields, then assume it already
-                * been converted.
-                */
-               if (uprf (name, XXX_FIELD_PRF)) {
-                   fclose (fp);
-                   m_getfld_state_destroy (&gstate);
-                   return 0;
-               }
-               while (state == FLDPLUS) {
-                   bufsz = sizeof buf;
-                   state = m_getfld (&gstate, name, buf, &bufsz, fp);
-               }
-               break;
-
-           case BODY:
-               do {
-                   char *bp;
-
-                   for (bp = buf; *bp; bp++)
-                       if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
-                           fclose (fp);
-                           m_getfld_state_destroy (&gstate);
-                           return 1;
-                       }
-
-                   bufsz = sizeof buf;
-                   state = m_getfld (&gstate, name, buf, &bufsz, fp);
-               } while (state == BODY);
-               /* and fall... */
-
-           default:
-               fclose (fp);
-               m_getfld_state_destroy (&gstate);
-               return 0;
-       }
-    }
-}
-
-
 #ifndef CYRUS_SASL
 # define SASLminc(a) (a)
 #else /* CYRUS_SASL */
@@ -1061,9 +973,6 @@ sendit (char *sp, char **arg, char *file, int pushed)
     char *cp, buf[BUFSIZ], **argp, *program;
     char **arguments, *savearg[MAXARGS], **vec;
     struct stat st;
-    char       *attach = NMH_ATTACH_HEADER;/* attachment header field name */
-    int                attachformat = 1;       /* mhbuild format specifier for
-                                          attachments */
 
 #ifndef        lint
     int        distsw = 0;
@@ -1241,28 +1150,14 @@ sendit (char *sp, char **arg, char *file, int pushed)
                    continue;
 
                case SNDATTACHSW:
-                   if (!(attach = *argp++) || *attach == '-') {
-                       advise (NULL, "missing argument to %s", argp[-2]);
-                       return;
-                   }
+                   advise(NULL, "The -attach switch is deprecated");
                    continue;
                case SNDNOATTACHSW:
-                   attach = NULL;
+                   advise(NULL, "The -noattach switch is deprecated");
                    continue;
 
                case SNDATTACHFORMAT:
-                   if (! *argp || **argp == '-')
-                       adios (NULL, "missing argument to %s", argp[-1]);
-                   else {
-                       attachformat = atoi (*argp);
-                       if (attachformat < 0 ||
-                           attachformat > ATTACHFORMATS - 1) {
-                           advise (NULL, "unsupported attachformat %d",
-                                   attachformat);
-                           continue;
-                       }
-                   }
-                   ++argp;
+                   advise(NULL, "The -attachformat switch is deprecated");
                    continue;
            }
        }
@@ -1299,12 +1194,8 @@ sendit (char *sp, char **arg, char *file, int pushed)
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
-       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
-       }
-       distfile = getcpy (cp);
-       (void) m_unlink(distfile);
+       distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
+       unlink(distfile);
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
     } else {
@@ -1321,7 +1212,7 @@ sendit (char *sp, char **arg, char *file, int pushed)
 
     closefds (3);
 
-    if (sendsbr (vec, vecp, program, file, &st, 1, attach, attachformat) == OK)
+    if (sendsbr (vec, vecp, program, file, &st, 1) == OK)
        done (0);
 }
 
@@ -1370,7 +1261,7 @@ whomfile (char **arg, char *file)
 static int
 removefile (char *drft)
 {
-    if (m_unlink (drft) == NOTOK)
+    if (unlink (drft) == NOTOK)
        adios (drft, "unable to unlink");
 
     return OK;
index 2a36025..8973c76 100644 (file)
@@ -63,7 +63,11 @@ main (int argc, char **argv)
     char *msg = NULL, **ap, **argp, backup[BUFSIZ];
     char buf[BUFSIZ], **arguments, *vec[MAXARGS];
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    setlocale(LC_ALL, "");
+    invo_name = r1bindex (argv[0], '/');
+
+    /* read user profile/context */
+    context_read();
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -196,7 +200,7 @@ main (int argc, char **argv)
 
            status = pidwait(child_id, OK);
 
-           (void) m_unlink (msg);
+           unlink (msg);
            if (rename (backup, msg) == NOTOK)
                adios (msg, "unable to rename %s to", backup);
            done (status);