MHSTORE(1mh)
π MHSTORE π
okay bestie, welcome to mhstore(1mh) β the nmh tool that stores the contents of your MIME (multi-media) messages into files. that's the whole vibe. let's get into it π«Ά
β¨ NAME β¨
mhstore β store contents of nmh MIME messages into files
πΈ SYNOPSIS πΈ
mhstore [-help] [-version] [+folder] [msgs] [-file file] [-outfile
outfile] [-part number] ... [-type content] ... [-prefer content]
... [-noprefer] [-auto | -noauto] [-clobber always | auto | suffix
| ask | never] [-verbose | -noverbose]
π DESCRIPTION π
so mhstore is the command that lets you store the contents of a collection of MIME (multi-media) messages into files or other messages. iconic behavior, no notes.
it manipulates multi-media messages as specified in RFC 2045 to RFC 2049. yes, all of them. she's thorough π
by default, mhstore will store all the parts of each message. each part gets its own separate file. the header fields of the message are not stored. if you wanna limit or reorder which parts get stored β based on part number and/or content type β you use the -part, -type, and -prefer switches. mix and match, bestie.
the -file file switch tells mhstore to use that specified file as the source message instead of pulling a message from a folder. and if you pass - as that file, mhstore will accept the source message on the standard input π. heads up tho: the file (or the stdin input) should be a validly formatted message, just like any other nmh message. it should not be in mail drop format. (to convert a file in mail drop format to a folder of nmh messages, see inc(1).)
ok so a part specification? it's a series of numbers separated by dots. for example, in a multipart content containing three parts, these would be named as 1, 2, and 3, respectively. if part 2 was also a multipart content containing two parts, those would be named as 2.1 and 2.2, respectively. note that the -part switch is effective only for messages containing a multipart content. if a message has some other kind of content, or if the part is itself another multipart content, the -part switch will not prevent the content from being acted upon. she does what she wants π
the -type switch can also be used to restrict (or, when used in conjunction with -part, to further restrict) the selection of parts according to content type. one or more -type switches will only select the first match from a multipart/alternative, even if there is more than one subpart that matches (one of) the given content type(s).
using either -part or -type switches alone will cause either to select the part(s) they match. using them together will select only the part(s) matched by both (sets of) switches. in other words, the result is the intersection, and not the union, of their separate match results. math ate, honestly.
a content specification consists of a content type and a subtype. the initial list of "standard" content types and subtypes can be found in RFC 2046.
a list of commonly used contents is briefly reproduced here:
textβplain,enrichedmultipartβmixed,alternative,digest,parallelmessageβrfc822,external-bodyapplicationβoctet-stream,postscriptimageβjpeg,gif,pngaudioβbasicvideoβmpeg
a legal MIME message must contain a subtype specification. periodt.
to specify a content regardless of its subtype, just use the name of the content, e.g., audio. to specify a specific subtype, separate the two with a slash, e.g., audio/basic. now listen: regardless of the values given to the -type switch, a multipart content (of any subtype listed above) is always acted upon. also β if the -type switch is used, and it's desirable to act on a message/external-body content, then the -type switch must be used twice: once for message/external-body and once for the content externally referenced. two switches, one vibe.
the -prefer switch will alter the part-ordering of multipart/alternative MIME sections in order to override the sender-imposed default ordering. the -prefer switch is functionally most important for mhshow, but is also implemented in mhlist and mhstore to make common part-numbering possible across all three programs. the last of multiple -prefer switches will have the highest priority β which is great, because it lets the command line switches override profile entries. see mhlist(1) and mhshow(1) for more information on -prefer.
the -noprefer switch will cancel any previous -prefer switches. she said never mind π
π Storing the Contents π
mhstore will store the contents of the named messages in "native" (decoded) format. two things must be determined: the directory in which to store the content, and the filenames. files are written in the directory given by the nmh-storage profile entry, e.g.,
nmh-storage: /tmp
if this entry isn't present, the current working directory is used.
if the -outfile switch is given, its argument is used for the filename to store all of the content, with - indicating standard output.
if the -auto switch is given, then mhstore will check if the message contains information indicating the filename that should be used to store the content. this information should be specified as the filename attribute in the Content-Disposition header or as the name attribute in the Content-Type header for the content you are storing.
β οΈ SECURITY CHECK, BESTIE β οΈ for security reasons, this filename will be ignored if it begins with the character/,.,|, or!, or if it contains the character%. we also recommend using anmh-storageprofile entry or a-clobberswitch setting other than the default ofalwaysto avoid overwriting existing files.
if the -auto switch is not given (or is being ignored for security reasons) then mhstore will look in the user's profile for a "formatting string" to determine how the different contents should be stored.
first, mhstore will look for an entry of the form:
mhstore-store-<type>/<subtype>
to determine the formatting string. if this isn't found, mhstore will look for an entry of the form:
mhstore-store-<type>
to determine the formatting string.
if the formatting string starts with a + character, then content is stored in the named folder. a formatting string consisting solely of a + character is interpreted to be the current folder.
if the formatting string consists solely of a - character, then the content is sent to the standard output.
if the formatting string starts with a |, then it represents a command for mhstore to execute which should ultimately store the content. the content will be passed to the standard input of the command. before the command is executed, mhstore will change to the appropriate directory, and any escapes (given below) in the formatting string will be expanded.
π¨ the use of the%asequence is not recommended because the user has no control over theContent-Typeparameter data. fr fr, don't do it.
otherwise, the formatting string will represent a pathname in which to store the content. if the formatting string starts with a /, then the content will be stored in the full path given, else the file name will be relative to the value of nmh-storage or the current working directory. any escapes (given below) will be expanded, except for the a-escape. note that if nmh-storage is not an absolute path, it will be relative to the folder that contains the message(s).
a command or pathname formatting string may contain the following escapes. if the content isn't part of a multipart (of any subtype listed above) content, the p-escapes are ignored.
%aβ Parameters fromContent-Type(only valid with command)%mβ Insert message number%Pβ Insert part number with leading dot%pβ Insert part number without leading dot%tβ Insert content type%sβ Insert content subtype%%β Insert character%
if no formatting string is found, mhstore will check to see if the content is application/octet-stream with parameter type=tar. if so, mhstore will choose an appropriate filename. if the content is not application/octet-stream, then mhstore will check to see if the content is a message. if so, mhstore will use the value +. as a last resort, mhstore will use the value %m%P.%s. she's got backup plans for her backup plans π
example profile entries might be:
mhstore-store-text: %m%P.txt
mhstore-store-text: +inbox
mhstore-store-audio/basic: | raw2audio -e ulaw -s 8000 -c 1 > %m%P.au
mhstore-store-image/jpeg: %m%P.jpg
mhstore-store-application/PostScript: %m%P.ps
the -verbose switch directs mhstore to print out the names of files that it stores. for backward compatibility, it is the default. the -noverbose switch suppresses these printouts.
π¦ Overwriting Existing Files π¦
the -clobber switch controls whether mhstore should overwrite existing files. the allowed values for this switch and the corresponding behavior when mhstore encounters an existing file are:
alwaysβ Overwrite existing file (default)autoβ Create new file of formname-n.extensionsuffixβ Create new file of formname.extension.naskβ Prompt the user to specify whether or not to overwrite the existing fileneverβ Do not overwrite existing file
with auto and suffix, n is the lowest unused number, starting from one, in the same form. if a filename does not have an extension (following a .), then auto and suffix create a new file of the form name-n and name.n, respectively. with never and ask, the exit status of mhstore will be the number of files that were requested but not stored. slay, numbers as exit codes π
with ask, if standard input is connected to a terminal, the user is prompted to respond yes, no, or rename, to whether the file should be overwritten. the responses can be abbreviated. if the user responds with rename, then mhstore prompts the user for the name of the new file to be created. if it is a relative path name (does not begin with /), then it is relative to the current directory. if it is an absolute or relative path to a directory that does not exist, the user will be prompted whether to create the directory. if standard input is not connected to a terminal, ask behaves the same as always. π
π External Access π
for contents of type message/external-body, mhstore supports these access-types:
afsanon-ftpftplocal-filemail-serverurl
for the anon-ftp and ftp access types, mhstore will look for the nmh-access-ftp profile entry, e.g.,
nmh-access-ftp: myftp.sh
okay bestie we're picking up mid-thought, no biggie, keep up π
to figure out the pathname of a program that does the FTP retrieval, mhstore invokes that program with these arguments:
domain name of FTP-site
username
password
remote directory
remote filename
local filename
βasciiβ or βbinaryβ
and the program should bail out with an exit status of zero if the retrieval slayed, and a non-zero exit status if it did not. no cap.
for the βurlβ access types, mhstore goes looking for the nmh-access-url profile entry, like, for example:
nmh-access-url: curl -L
and that's how it knows which program to use for the HTTP retrieval. this program gets invoked with one argument: the URL of the content to retrieve. it should write the content to standard out, and it should terminate with a status of zero if the retrieval is successful and a non-zero exit status otherwise. periodt.
πΈ User Environment πΈ
because the environment mhstore operates in may vary for different machines (it's giving "every laptop is a different girlie"), mhstore will look for the environment variable MHSTORE. if present, this specifies the name of an additional user profile which should be read. so basically, when a user logs in on a particular machine, this environment variable should be set to refer to a file containing definitions useful for that machine. iconic, honestly.
and finally, mhstore will attempt to consult
/etc/nmh/mhn.defaults
which is created automatically during nmh installation. β¨
see "Profile Lookup" in mh-profile(5) for the profile search order, and for how duplicate entries are treated. iykyk π«Ά
π EXAMPLES π
Decoding RFC 2047-encoded file names π
the improper RFC 2047 encoding of file name parameters can be replaced with correct RFC 2231 encoding using mhfixmsg, either permanently or ephemerally, e.g.,
mhfixmsg -outfile - | mhstore -auto -clobber ask -file -
the -clobberask is not necessary, though recommended to avoid silently overwriting an existing file. and bestie, "silently overwriting an existing file" is the kind of chaos we simply do not need in our lives π
π¦ FILES π¦
mhstore looks for additional profile files in multiple locations: absolute pathnames are accessed directly, tilde expansion is done on usernames, and files are searched for in the user's Mail directory as specified in their profile. if not found there, the directory β/etc/nmhβ is checked.
$HOME/.mh_profileβ the user profile$MHSTOREβ additional profile entries/etc/nmh/mhn.defaultsβ system default MIME profile entries
π PROFILE COMPONENTS π
Path:β to determine the user's nmh directoryCurrent-Folder:β to find the default current foldernmh-access-ftp:β program to retrieve contents via FTPnmh-access-url:β program to retrieve contents via HTTPnmh-storageβ directory to store contentsmhstore-store-<type>* β template for storing contents
π SEE ALSO π
mhbuild(1), mhfixmsg(1), mhlist(1), mhshow(1), sendfiles(1)
β DEFAULTS β
+folderdefaults to the current foldermsgsdefaults tocur-noauto-clobber always-verbose
π§ CONTEXT π§
if a folder is given, it will become the current folder. the last message selected will become the current message. main character behavior, honestly π
π BUGS π
partial messages contained within a multipart content are not reassembled. yeah. we know. we're all pretending we didn't see it π
and that's the whole page, bestie! this was MHSTORE(1mh) from the nmh-1.8 era, dated 2015-02-06 β a classic, an icon, a moment in time πβ¨π go forth and store your MIME content responsibly π«Ά
π¦ where this page comes from
- debian trixie: nmh 1.8-3
- ubuntu noble: nmh 1.8-1build4
- ubuntu questing: nmh 1.8-3
- ubuntu resolute: nmh 1.8-4
- ubuntu stonking: nmh 1.8-4build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms