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 \
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)
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
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
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 \
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
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)
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
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
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 \
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],
[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>.]),,
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 \
+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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
-------------------------
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
--------------
[ "$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.
> /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$$
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
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
extern struct swit anoyes[]; /* standard yes/no switches */
-#define ATTACHFORMATS 3 /* Number of send attach formats. */
-
/*
* general folder attributes
*/
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);
#define LINK "@" /* Name of link to file to which you are */
/* replying. */
-#define NMH_ATTACH_HEADER "Nmh-Attachment" /* Default header for -attach */
-
/*
* credentials management
*/
* 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
* -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);
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
*/
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);
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);
.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
(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
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
-.TH MHBUILD %manext1% "March 21, 2013" "%nmhversion%"
+.TH MHBUILD %manext1% "January 23, 2014" "%nmhversion%"
.\"
.\" %nmhwarning%
.\"
.RB [ \-headerencoding
.IR encoding\-algorithm
.RB " | " \-autoheaderencoding ]
+.RB [ \-dist ]
.RB [ \-version ]
.RB [ \-help ]
.ad
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
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
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
.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
-.TH MHPATH %manext1% "November 6, 2012" "%nmhversion%"
+.TH MHPATH %manext1% "January 20, 2014" "%nmhversion%"
.\"
.\" %nmhwarning%
.\"
/r/phyl/Mail
.fi
.RE
+.PP
Because
.B mhpath
expands and sorts
.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"
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
.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
.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 ,
.\"
.\" %nmhwarning%
.\"
-.TH SEND %manext1% "December 22, 2013" "%nmhversion%"
+.TH SEND %manext1% "January 23, 2014" "%nmhversion%"
.SH NAME
send \- send a message
.SH SYNOPSIS
\&...]
.RB [ \-version ]
.RB [ \-help ]
-.RB [ \-attach
-.IR header-field-name ]
-.RB [ \-noattach ]
-.RB [ \-attachformat
-.IR 0 " | " 1 " | " 2 ]
.ad
.SH DESCRIPTION
.B Send
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
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
.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
.RB ` \-noverbose '
.RB ` \-nowatch '
.RB ` "\-width\ 72" '
-.RB ` "\-attach\ Nmh-Attachment" '
-.RB ` "\-attachformat\ 1" '
.fi
.SH CONTEXT
None
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
.RI [ file ]
.RB [ \-version ]
.RB [ \-help ]
-.RB [ \-attach
-.IR header-field-name ]
-.RB [ \-noattach ]
.ad
.SH DESCRIPTION
.B Whatnow
^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
.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,
*/
#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));
}
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 */
}
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;
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] = '_';
}
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;
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;
}
if (unlink_msgs) {
/* just unlink the messages */
- if (m_unlink (dp) == -1) {
+ if (unlink (dp) == -1) {
admonish (dp, "unable to unlink");
retval = -1;
continue;
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;
}
}
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 */
/* check for stale lockfile, else sleep */
if (curtime > st.st_ctime + RSECS)
- (void) m_unlink (lkinfo.curlock);
+ unlink (lkinfo.curlock);
else
sleep (5);
}
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 */
* 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);
}
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;
snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
BACKUP_PREFIX, cp);
- (void) m_unlink(buffer);
+ unlink(buffer);
return buffer;
}
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++;
}
*/
#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).
*
* When pfx_in is null, the temporary directory is determined as
* follows, in order:
- *
+ *
* MHTMPDIR envvar
* TMPDIR envvar
* TMP envvar
}
fd = mkstemp(tmpfil);
-
if (fd < 0) {
umask(oldmode);
return NULL;
}
-
- register_for_removal(tmpfil);
-
if (fd_ret != NULL) {
*fd_ret = fd;
keep_open = 1;
FILE *fp = fdopen(fd, "w+");
if (fp == NULL) {
int olderr = errno;
- (void) m_unlink(tmpfil);
+ unlink(tmpfil);
close(fd);
errno = olderr;
umask(oldmode);
* 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()
}
-char *
+static char *
get_temp_dir()
{
/* Ignore envvars if we are setuid */
}
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);
- }
-}
--- /dev/null
+/*
+ * 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 */
SIGNAL (SIGTTIN, SIG_IGN);
SIGNAL (SIGTTOU, SIG_IGN);
#endif
-
- unregister_for_removal(0);
-
freopen ("/dev/null", "r", stdin);
freopen ("/dev/null", "w", stdout);
break;
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;
* public sequences, then remove that file.
*/
if (!is_readonly(mp))
- (void) m_unlink (seqfile);
+ unlink (seqfile);
}
/*
#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
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;
-}
#include <h/mh.h>
-#ifndef LOCALE
-# define TO_LOWER 040
-# define NO_MASK 000
-#endif
-
int
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++;
#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.
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;
- }
-}
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;
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
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}
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.
------
EOF
-mhbuild "$draft"
+run_prog mhbuild "$draft"
-cat > "$actual" <<EOF
+cat > "$expected" <<EOF
To: Mr Test <mrtest@example.com>
cc:
Fcc: +outbox
/9g=
EOF
-check "$draft" "$actual"
+check "$draft" "$expected"
#
# Check out more common case, one (or more) attachments
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}
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
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
DATA
To: recipient@example.com
From: sender8@localhost
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
Date:
Message-ID:
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"
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
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:
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:
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
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
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
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
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
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.
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.
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.
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
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
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.
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.
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.
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.
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.
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
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.
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.
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
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
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.
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.
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
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
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
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
# 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"
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
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
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);
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;
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);
/*
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:
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);
+++ /dev/null
-/*
- * 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;
-}
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;
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);
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;
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);
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;
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;
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;
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;
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;
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;
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;
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
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;
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;
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
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;
}
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");
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);
} else {
if (ferror(pf) || fclose (pf)) {
int e = errno;
- (void) m_unlink (cp);
+ unlink (cp);
pop_quit ();
errno = e;
adios (cp, "write error on");
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);
}
}
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 */
}
close (newfd);
else
admonish (newmail, "error zero'ing");
- (void) m_unlink(map_name(newmail));
+ unlink(map_name(newmail));
}
} else {
if (noisy)
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;
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;
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);
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;
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;
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;
case DEBUGSW:
debugsw = 1;
continue;
+ case DISTSW:
+ dist = 1;
+ continue;
}
}
if (compfile)
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));
* 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
free_content (ct);
}
- (void) m_unlink (infile);
+ unlink (infile);
unlink_infile = 0;
done (0);
*/
/* 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
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 */
* temporary files.
*/
if (unlink_infile)
- (void) m_unlink (infile);
+ unlink (infile);
if (unlink_outfile)
- (void) m_unlink (outfile);
+ unlink (outfile);
exit (status);
}
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";
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);
*/
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];
entry = mh_xmalloc(sizeof(*entry));
entry->filename = getcpy(s);
+ entry->next = NULL;
free(vp);
+
if (attach_tail) {
attach_tail->next = entry;
attach_tail = entry;
* 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
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;
}
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.
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
}
/* Build the rest of the header field structures */
- build_headers (ct);
+ if (! dist)
+ build_headers (ct);
return ct;
}
*/
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;
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);
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;
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;
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);
if (status == OK && writing) {
if (*writing && strchr(buffer, '/'))
make_intermediates (buffer);
- (void) m_unlink (buffer);
+ unlink (buffer);
}
free (id);
#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 */
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;
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"))
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");
}
}
status += mhfixmsgsbr (ctp, &fx, outfile);
if (using_stdin) {
- (void) m_unlink (file);
+ unlink (file);
if (! outfile) {
/* Just calling m_backup() unlinks the backup file. */
}
free (outfile);
+ free (tmp);
free (file);
/* done is freects_done, which will clean up all of cts. */
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");
}
}
if (modify_inplace) {
- if (status != OK) (void) m_unlink (outfile);
+ if (status != OK) unlink (outfile);
free (outfile);
outfile = NULL;
}
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);
status = NOTOK;
}
} else {
- advise (NULL, "unable to create temporary file in %s",
- get_temp_dir());
+ advise (NULL, "unable to create temporary file");
status = NOTOK;
}
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,
}
free_content (tp_part);
- (void) m_unlink (tmp_plain_file);
+ unlink (tmp_plain_file);
free (tmp_plain_file);
return NULL;
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;
/* 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;
: 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 &&
: 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 (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);
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);
}
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) {
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;
/* 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);
}
}
}
} else {
- (void) m_unlink (dest);
+ unlink (dest);
}
#else /* ! HAVE_ICONV */
NMH_UNUSED (message_mods);
}
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
} else {
admonish (NULL, "unable to remove input file %s, "
"not modifying it", infile);
- (void) m_unlink (outfile);
+ unlink (outfile);
status = NOTOK;
}
}
} 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
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)
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;
}
int
main (int argc, char **argv)
{
- if (nmh_init(argv[0], 1)) { return 1; }
-
+ setlocale(LC_ALL, "");
done (mhl (argc, argv));
return 1;
}
#undef X
+/* mhparse.c */
+extern char *tmp; /* directory to place temp files */
+
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
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;
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));
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;
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
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 ;;
#undef X
+/* mhparse.c */
+extern char *tmp; /* directory to place temp files */
+
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
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;
*/
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));
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;
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
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;
}
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;
}
}
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);
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);
}
}
}
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);
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);
}
}
}
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);
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);
}
}
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);
}
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");
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);
}
}
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);
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");
if (ferror(gp)) {
admonish(ce->ce_file, "error reading");
- (void) m_unlink (cachefile);
+ unlink(cachefile);
}
}
umask(mask);
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;
#undef X
+/* mhparse.c */
+extern char *tmp; /* directory to place temp files */
+
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
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;
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));
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;
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;
*/
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));
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 */
*/
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;
}
#undef X
+/* mhparse.c */
+extern char *tmp; /* directory to place temp files */
+
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
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;
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));
pipeser (int i)
{
if (i == SIGQUIT) {
+ unlink ("core");
fflush (stdout);
fprintf (stderr, "\n");
fflush (stderr);
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);
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);
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;
}
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);
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);
}
}
break;
}
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
}
}
if (!fmsh)
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
return status;
}
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;
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;
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;
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);
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);
}
}
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)
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);
{
NMH_UNUSED (i);
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
if (msgflags & MINV)
- (void) m_unlink (bccfil);
+ unlink (bccfil);
if (!whomsw || checksw)
sm_end (NOTOK);
{
va_list ap;
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
if (msgflags & MINV)
- (void) m_unlink (bccfil);
+ unlink (bccfil);
if (!whomsw || checksw)
sm_end (NOTOK);
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;
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?
if (killp || erasep) {
tcsetattr(0, TCSADRAIN, &tio);
}
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
done (1);
}
if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
cpydata (fdi, fdo, tmpfil, drft);
close (fdi);
close (fdo);
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
context_save (); /* save the context file */
done (0);
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
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);
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);
}
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);
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;
/* 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());
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)
/* 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);
}
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);
unlink_done(int status)
{
if (tmpfilenam && *tmpfilenam)
- (void) m_unlink (tmpfilenam);
+ unlink (tmpfilenam);
exit (status);
}
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);
{
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 */
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);
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;
/* 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");
}
}
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;
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;
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++;
}
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;
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);
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) \
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;
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 {
&& (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
)
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;
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:
#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>
static jmp_buf env;
-/*
- * external prototypes
- */
-int sendsbr (char **, int, char *, char *, struct stat *, int, char *, int);
-char *getusername (void);
-
/*
* static prototypes
*/
*/
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;
* 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;
* 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;
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;
}
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
snprintf (partnum, sizeof(partnum), "%d", partno);
status = sendaux (vec, vecp, program, tmpdrf, st);
- (void) m_unlink (tmpdrf);
+ unlink (tmpdrf);
if (status != OK)
break;
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)
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);
}
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;
sigaddset (&set, SIGTERM);
sigprocmask (SIG_BLOCK, &set, &oset);
- unregister_for_removal(0);
-
annoaux (fd);
if (child_id == OK)
_exit (0);
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;
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);
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)
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");
tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
if (tfile == NULL) return -1;
+ fchmod(fd1, 0600);
strncpy (tmpfil, tfile, BUFSIZ);
if (!fold) {
if (write (fd1, buffer, i) != i) {
you_lose:
close (fd1);
- (void) m_unlink (tmpfil);
+ unlink (tmpfil);
return -1;
}
if (i == -1)
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;
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;
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 */
}
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, '@'))
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++;
}
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;
}
int
main (int argc, char **argv)
{
- if (nmh_init(argv[0], 1)) { return 1; }
-
+ setlocale(LC_ALL, "");
return WhatNow (argc, argv);
}
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);
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 **);
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 */
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;
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;
}
}
#else /* ! READLINE_SUPPORT */
if (!(argp = getans (prompt, aleqs))) {
#endif /* READLINE_SUPPORT */
- (void) m_unlink (LINK);
+ unlink (LINK);
done (1);
}
switch (smatch (*argp, aleqs)) {
* -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;
advise((char *)0, "usage is alist [-ln].");
else
- annolist(drft, attach, l, n);
+ annolist(drft, ATTACH_FIELD, l, n);
break;
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;
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);
}
}
* 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.
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) {
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 {
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;
&& 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);
}
*ed = NULL;
if (altmsg && atfile)
- (void) m_unlink (linkpath);
+ unlink (linkpath);
return status;
}
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.
}
-/*
- * 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 */
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;
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;
}
}
#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 {
closefds (3);
- if (sendsbr (vec, vecp, program, file, &st, 1, attach, attachformat) == OK)
+ if (sendsbr (vec, vecp, program, file, &st, 1) == OK)
done (0);
}
static int
removefile (char *drft)
{
- if (m_unlink (drft) == NOTOK)
+ if (unlink (drft) == NOTOK)
adios (drft, "unable to unlink");
return OK;
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;
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);