From: Ken Hornstein Date: Fri, 24 Jan 2014 18:17:56 +0000 (-0500) Subject: Move uip/attach.c to sbr/mime_type.c; it was used by enough programs X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/146835943204559707b5461859837cb51fd3485a?ds=sidebyside;hp=--cc Move uip/attach.c to sbr/mime_type.c; it was used by enough programs that it deserved to be in libmh. --- 146835943204559707b5461859837cb51fd3485a diff --git a/Makefile.am b/Makefile.am index 05b6559f..626fd829 100644 --- a/Makefile.am +++ b/Makefile.am @@ -290,11 +290,11 @@ uip_burst_SOURCES = uip/burst.c uip/mhparse.c uip/mhmisc.c uip/mhfree.c \ uip_burst_LDADD = $(LDADD) $(POSTLINK) uip_comp_SOURCES = uip/comp.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \ - uip/attach.c uip/annosbr.c uip/distsbr.c + uip/annosbr.c uip/distsbr.c uip_comp_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_dist_SOURCES = uip/dist.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \ - uip/attach.c uip/annosbr.c uip/distsbr.c uip/forwsbr.c + uip/annosbr.c uip/distsbr.c uip/forwsbr.c uip_dist_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_flist_SOURCES = uip/flist.c @@ -304,7 +304,7 @@ uip_folder_SOURCES = uip/folder.c uip_folder_LDADD = $(LDADD) $(POSTLINK) uip_forw_SOURCES = uip/forw.c uip/whatnowproc.c uip/whatnowsbr.c uip/sendsbr.c \ - uip/attach.c uip/annosbr.c uip/distsbr.c uip/forwsbr.c + uip/annosbr.c uip/distsbr.c uip/forwsbr.c uip_forw_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_inc_SOURCES = uip/inc.c uip/scansbr.c uip/dropsbr.c uip/popsbr.c @@ -318,7 +318,7 @@ uip_mark_LDADD = $(LDADD) $(POSTLINK) uip_mhbuild_SOURCES = uip/mhbuild.c uip/mhbuildsbr.c uip/mhcachesbr.c \ uip/mhlistsbr.c uip/mhoutsbr.c uip/mhmisc.c \ - uip/mhfree.c uip/mhparse.c uip/md5.c uip/attach.c + uip/mhfree.c uip/mhparse.c uip/md5.c uip_mhbuild_LDADD = $(LDADD) $(TERMLIB) $(POSTLINK) uip_mhfixmsg_SOURCES = uip/mhfixmsg.c uip/mhparse.c uip/mhcachesbr.c \ @@ -374,7 +374,7 @@ uip_refile_SOURCES = uip/refile.c uip_refile_LDADD = $(LDADD) $(POSTLINK) uip_repl_SOURCES = uip/repl.c uip/replsbr.c uip/whatnowproc.c uip/whatnowsbr.c \ - uip/sendsbr.c uip/attach.c uip/annosbr.c uip/distsbr.c + uip/sendsbr.c uip/annosbr.c uip/distsbr.c uip_repl_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_rmf_SOURCES = uip/rmf.c @@ -386,7 +386,7 @@ uip_rmm_LDADD = $(LDADD) $(POSTLINK) uip_scan_SOURCES = uip/scan.c uip/scansbr.c uip_scan_LDADD = $(LDADD) $(TERMLIB) $(ICONVLIB) $(POSTLINK) -uip_send_SOURCES = uip/send.c uip/sendsbr.c uip/attach.c uip/annosbr.c \ +uip_send_SOURCES = uip/send.c uip/sendsbr.c uip/annosbr.c \ uip/distsbr.c uip_send_LDADD = $(LDADD) $(POSTLINK) @@ -397,7 +397,7 @@ uip_sortm_SOURCES = uip/sortm.c uip_sortm_LDADD = $(LDADD) $(POSTLINK) uip_whatnow_SOURCES = uip/whatnow.c uip/whatnowsbr.c uip/sendsbr.c \ - uip/attach.c uip/annosbr.c uip/distsbr.c + uip/annosbr.c uip/distsbr.c uip_whatnow_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(POSTLINK) uip_whom_SOURCES = uip/whom.c uip/distsbr.c @@ -449,7 +449,7 @@ uip_slocal_SOURCES = uip/slocal.c uip/aliasbr.c uip/dropsbr.c uip_slocal_LDADD = $(LDADD) $(NDBM_LIBS) $(POSTLINK) uip_viamail_SOURCES = uip/viamail.c uip/mhmisc.c uip/mhoutsbr.c uip/sendsbr.c \ - uip/attach.c uip/annosbr.c uip/distsbr.c + uip/annosbr.c uip/distsbr.c uip_viamail_LDADD = $(LDADD) $(POSTLINK) test_getfullname_SOURCES = test/getfullname.c @@ -569,7 +569,7 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/arglist.c \ sbr/m_atoi.c sbr/m_backup.c sbr/m_convert.c \ sbr/m_draft.c sbr/m_getfld.c sbr/m_gmprot.c \ sbr/m_maildir.c sbr/m_name.c sbr/m_rand.c \ - sbr/makedir.c sbr/message_id.c sbr/mts.c \ + sbr/makedir.c sbr/message_id.c sbr/mime_type.c sbr/mts.c \ sbr/norm_charmap.c sbr/path.c \ sbr/peekc.c sbr/pidwait.c sbr/pidstatus.c \ sbr/print_help.c sbr/print_sw.c sbr/print_version.c \ diff --git a/h/prototypes.h b/h/prototypes.h index a8f6d468..a4184312 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -195,6 +195,26 @@ 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 */ @@ -345,14 +365,6 @@ int writeBase64aux(FILE *, FILE *); int writeBase64 (unsigned char *, size_t, unsigned char *); int writeBase64raw (unsigned char *, size_t, unsigned char *); -/* - * prototypes to support whatnow attach - */ -int attach(char *, char *, char *, size_t, char *, size_t, int); -void clean_up_temporary_files(const char *, const char *); -char *mime_type(const char *); -char *construct_build_directive(char *, const char *, int); - /* * credentials management */ diff --git a/uip/attach.c b/sbr/mime_type.c similarity index 94% rename from uip/attach.c rename to sbr/mime_type.c index 540ddd93..be791096 100644 --- a/uip/attach.c +++ b/sbr/mime_type.c @@ -1,7 +1,7 @@ /* - * attach.c -- routines to help attach files via whatnow + * mime_type.c -- routine to determine the MIME Content-Type of a file * - * This code is Copyright (c) 2002, by the authors of nmh. See the + * 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. */ @@ -16,7 +16,8 @@ static char *get_file_info(const char *, const char *); /* * Try to use external command to determine mime type, and possibly - * encoding. Caller is responsible for free'ing returned memory. + * encoding. If that fails try using the filename extension. Caller + * is responsible for free'ing returned memory. */ char * mime_type(const char *file_name) {