]> diplodocus.org Git - nmh/blob - man/mhstore.man
6750584b0726bdb771df45bc3c34e681e4d585d5
[nmh] / man / mhstore.man
1 .TH MHSTORE %manext1% 2015-02-06 "%nmhversion%"
2 .
3 .\" %nmhwarning%
4 .
5 .SH NAME
6 mhstore \- store contents of nmh MIME messages into files
7 .SH SYNOPSIS
8 .HP 5
9 .na
10 .B mhstore
11 .RB [ \-help ]
12 .RB [ \-version ]
13 .RI [ +folder ]
14 .RI [ msgs ]
15 .RB [ \-file
16 .IR file ]
17 .RB [ \-outfile
18 .IR outfile ]
19 .RB [ \-part
20 .IR number ]
21 \&...
22 .RB [ \-type
23 .IR content ]
24 \&...
25 .RB [ \-prefer
26 .IR content ]
27 \&...
28 .RB [ \-noprefer ]
29 .RB [ \-auto " | " \-noauto ]
30 .RB [ \-clobber
31 .IR always " | " auto " | " suffix " | " ask " | " never ]
32 .RB [ \-verbose " | " \-noverbose ]
33 .ad
34 .SH DESCRIPTION
35 The
36 .B mhstore
37 command allows you to store the contents of a collection of MIME
38 (multi-media) messages into files or other messages.
39 .PP
40 .B mhstore
41 manipulates multi-media messages as specified in RFC 2045 to RFC 2049.
42 .PP
43 By default,
44 .B mhstore
45 will store all the parts of each message.
46 Each part will be stored in a separate file. The header fields of
47 the message are not stored. By using the
48 .BR \-part ,
49 .BR \-type ,
50 and
51 .B \-prefer
52 switches, you may limit and reorder the set of parts to be stored,
53 based on part number and/or content type.
54 .PP
55 The
56 .B \-file
57 .I file
58 switch directs
59 .B mhstore
60 to use the specified file as the source message, rather than a message
61 from a folder. If you specify this file as \*(lq-\*(rq, then
62 .B mhstore
63 will accept the source message on the standard input. Note that the
64 file, or input from standard input, should be a validly formatted
65 message, just like any other
66 .B nmh
67 message. It should
68 .I not
69 be in mail drop format (to convert a file in
70 mail drop format to a folder of
71 .B nmh
72 messages, see
73 .IR inc (1)).
74 .PP
75 A part specification consists of a series of numbers separated by
76 dots. For example, in a multipart content containing three parts,
77 these would be named as 1, 2, and 3, respectively. If part 2 was also
78 a multipart content containing two parts, these would be named as 2.1
79 and 2.2, respectively. Note that the
80 .B \-part
81 switch is effective only for messages containing a multipart content.
82 If a message has some other kind of content, or if the part is itself
83 another multipart content, the
84 .B \-part
85 switch will not prevent the content from being acted upon.
86 .PP
87 The
88 .B \-type
89 switch can also be used to restrict (or, when used in conjunction with
90 .BR \-part ,
91 to further restrict) the selection of parts according to content type.
92 One or more
93 .B \-type
94 switches part will only select the first match from a
95 multipart/alternative, even if there is more than one
96 subpart that matches (one of) the given content type(s).
97 .PP
98 Using either
99 .B \-part
100 or
101 .B -type
102 switches alone will cause either to select the part(s) they match.
103 Using them together will select only the part(s) matched by both
104 (sets of) switches. In other words, the result is the intersection,
105 and not the union, of their separate match results.
106 .PP
107 A content specification consists of a content type and a subtype.
108 The initial list of \*(lqstandard\*(rq content types and subtypes can
109 be found in RFC 2046.
110 .PP
111 A list of commonly used contents is briefly reproduced here:
112 .PP
113 .RS 5
114 .nf
115 .ta \w'application 'u
116 Type Subtypes
117 ---- --------
118 text plain, enriched
119 multipart mixed, alternative, digest, parallel
120 message rfc822, partial, external-body
121 application octet-stream, postscript
122 image jpeg, gif, png
123 audio basic
124 video mpeg
125 .fi
126 .RE
127 .PP
128 A legal MIME message must contain a subtype specification.
129 .PP
130 To specify a content, regardless of its subtype, just use the name
131 of the content, e.g., \*(lqaudio\*(rq. To specify a specific
132 subtype, separate the two with a slash, e.g., \*(lqaudio/basic\*(rq.
133 Note that regardless of the values given to the
134 .B \-type
135 switch, a multipart content (of any subtype listed above) is always acted
136 upon. Further note that if the
137 .B \-type
138 switch is used, and it is desirable to act on a message/external-body
139 content, then the
140 .B \-type
141 switch must be used twice: once for message/external-body and once for
142 the content externally referenced.
143 .PP
144 The
145 .B \-prefer
146 switch will alter the part-ordering of multipart/alternative MIME sections
147 in order to override the sender-imposed default ordering.
148 The
149 .B \-prefer
150 switch is functionally most important for
151 .BR mhshow ,
152 but is also implemented in
153 .B mhlist
154 and
155 .B mhstore
156 to make common part-numbering possible across all three programs.
157 The last of multiple
158 .B \-prefer
159 switches will have the highest priority. This allows the command line
160 switches to override profile entries.
161 See
162 .IR mhlist (1)
163 and
164 .IR mhshow (1)
165 for more information on
166 .BR \-prefer .
167 .PP
168 The
169 .B \-noprefer
170 switch will cancel any previous
171 .B \-prefer
172 switches.
173 .SS "Storing the Contents"
174 .B mhstore
175 will store the contents of the named messages in
176 \*(lqnative\*(rq (decoded) format. Two things must be determined:
177 the directory in which to store the content, and the filenames.
178 Files are written in the directory given by the
179 \*(lqnmh-storage\*(rq profile entry, e.g.,
180 .PP
181 .RS 5
182 nmh-storage: /tmp
183 .RE
184 .PP
185 If this entry isn't present, the current working directory is used.
186 .PP
187 If the
188 .B \-outfile
189 switch is given, its argument is used for the filename to store all
190 of the content, with \*(lq-\*(rq indicating standard output. If the
191 .B \-auto
192 switch is given, then
193 .B mhstore
194 will check if the message contains information indicating the filename
195 that should be used to store the content. This information should be
196 specified as the \*(lqfilename\*(rq attribute in the
197 \*(lqContent-Disposition\*(rq header or as the \*(lqname\*(rq
198 attribute in the \*(lqContent-Type\*(rq header for the content you are
199 storing. For security reasons, this filename will be ignored if it
200 begins with the character '/', '.', '|', or '!', or if it contains the
201 character '%'. We also recommend using a \*(lqnmh-storage\*(rq profile
202 entry or a
203 .B \-clobber
204 switch setting other than the default of \*(lqalways\*(rq to avoid
205 overwriting existing files.
206 .PP
207 If the
208 .B \-auto
209 switch is not given (or is being ignored for security reasons) then
210 .B mhstore
211 will look in the user's profile for a \*(lqformatting string\*(rq to
212 determine how the different contents should be stored. First,
213 .B mhstore
214 will look for an entry of the form:
215 .PP
216 .RS 5
217 mhstore-store-<type>/<subtype>
218 .RE
219 .PP
220 to determine the formatting string. If this isn't found,
221 .B mhstore
222 will look for an entry of the form:
223 .PP
224 .RS 5
225 mhstore-store-<type>
226 .RE
227 .PP
228 to determine the formatting string.
229 .PP
230 If the formatting string starts with a \*(lq+\*(rq character, then
231 content is stored in the named folder. A formatting string consisting
232 solely of a \*(lq+\*(rq character is interpreted to be the current
233 folder.
234 .PP
235 If the formatting string consists solely of a \*(lq-\*(rq character,
236 then the content is sent to the standard output.
237 .PP
238 If the formatting string starts with a '|', then it represents
239 a command for
240 .B mhstore
241 to execute which should ultimately store the content.
242 The content will be passed to the standard input of the command.
243 Before the command is executed,
244 .B mhstore
245 will change to the appropriate directory, and any escapes (given below)
246 in the formatting string will be expanded.
247 The use of the \*(lq%a\*(rq sequence is not recommended because
248 the user has no control over the Content-Type parameter data.
249 .PP
250 Otherwise, the formatting string will represent a pathname in which
251 to store the content. If the formatting string starts with a '/',
252 then the content will be stored in the full path given, else the
253 file name will be relative to the value of \*(lqnmh-storage\*(rq or
254 the current working directory. Any escapes (given below) will be
255 expanded, except for the a-escape. Note that if \*(lqnmh-storage\*(rq
256 is not an absolute path, it will be relative to the folder that
257 contains the message(s).
258 .PP
259 A command or pathname formatting string may contain the following
260 escapes. If the content isn't part of a multipart (of any subtype
261 listed above) content, the p-escapes are ignored.
262 .PP
263 .RS 5
264 .nf
265 .ta \w'%P 'u
266 %a Parameters from Content-Type (only valid with command)
267 %m Insert message number
268 %P Insert part number with leading dot
269 %p Insert part number without leading dot
270 %t Insert content type
271 %s Insert content subtype
272 %% Insert character %
273 .fi
274 .RE
275 .PP
276 If no formatting string is found,
277 .B mhstore
278 will check to see if the content is application/octet-stream with parameter
279 \*(lqtype=tar\*(rq. If so,
280 .B mhstore
281 will choose an appropriate filename. If the content is not
282 application/octet-stream, then
283 .B mhstore
284 will check to see if the content is a message. If so,
285 .B mhstore
286 will use the value \*(lq+\*(rq. As a last resort,
287 .B mhstore
288 will use the value \*(lq%m%P.%s\*(rq.
289 .PP
290 Example profile entries might be:
291 .PP
292 .RS 5
293 .nf
294 mhstore-store-text: %m%P.txt
295 mhstore-store-text: +inbox
296 mhstore-store-message/partial: +
297 mhstore-store-audio/basic: | raw2audio -e ulaw -s 8000 -c 1 > %m%P.au
298 mhstore-store-image/jpeg: %m%P.jpg
299 mhstore-store-application/PostScript: %m%P.ps
300 .fi
301 .RE
302 .PP
303 The
304 .B \-verbose
305 switch directs
306 .B mhstore
307 to print out the names of files that it stores. For backward
308 compatibility, it is the default. The
309 .B \-noverbose
310 switch suppresses these printouts.
311 .SS "Overwriting Existing Files"
312 The
313 .B \-clobber
314 switch controls whether
315 .B mhstore
316 should overwrite existing files. The allowed values for this switch
317 and corresponding behavior when
318 .B mhstore
319 encounters an existing file are:
320 .PP
321 .RS 5
322 .nf
323 .ta \w'suffix 'u
324 always Overwrite existing file (default)
325 auto Create new file of form name-n.extension
326 suffix Create new file of form name.extension.n
327 ask Prompt the user to specify whether or not to overwrite
328 the existing file
329 never Do not overwrite existing file
330 .fi
331 .RE
332 .PP
333 With
334 .I auto
335 and
336 .IR suffix ,
337 .I n
338 is the lowest unused number, starting from one, in the same form. If
339 a filename does not have an extension (following a '.'), then
340 .I auto
341 and
342 .I suffix
343 create a new file of the form
344 .I name-n
345 and
346 .IR name.n ,
347 respectively. With
348 .I never
349 and
350 .IR ask ,
351 the exit status of
352 .B mhstore
353 will be the number of files that were requested but not stored.
354 .PP
355 With
356 .IR ask ,
357 if standard input is connected to a terminal, the user is prompted to
358 respond
359 .IR yes ,
360 .IR no ,
361 or
362 .IR rename ,
363 to whether the file should be overwritten. The responses
364 can be abbreviated. If the user responds with
365 .IR rename ,
366 then
367 .B mhstore
368 prompts the user for the name of the new file to be created. If it is
369 a relative path name (does not begin with '/'), then it is relative to
370 the current directory. If it is an absolute or relative path to a
371 directory that does not exist, the user will be prompted whether to
372 create the directory. If standard input is not connected to a
373 terminal,
374 .I ask
375 behaves the same as
376 .IR always .
377 .SS "Reassembling Messages of Type message/partial"
378 .B mhstore
379 is also able to reassemble messages that have been
380 split into multiple messages of type \*(lqmessage/partial\*(rq.
381 .PP
382 When asked to store a content containing a partial message,
383 .B mhstore
384 will try to locate all of the portions and combine them accordingly.
385 The default is to store the combined parts as a new message in the
386 current folder, although this can be changed using formatting
387 strings as discussed above. Thus, if someone has sent you a
388 message in several parts (such as the output from
389 .BR sendfiles ),
390 you can easily reassemble them into a single message in the
391 following fashion:
392 .PP
393 .RS 5
394 .nf
395 $ mhlist 5-8
396 msg part type/subtype size description
397 5 message/partial 47K part 1 of 4
398 6 message/partial 47K part 2 of 4
399 7 message/partial 47K part 3 of 4
400 8 message/partial 18K part 4 of 4
401 $ mhstore 5-8
402 reassembling partials 5,6,7,8 to folder inbox as message 9
403 $ mhlist -verbose 9
404 msg part type/subtype size description
405 9 application/octet-stream 118K
406 (extract with uncompress | tar xvpf -)
407 type=tar
408 conversions=compress
409 .fi
410 .RE
411 .PP
412 This will store exactly one message, containing the sum of the
413 parts. It doesn't matter whether the partials are specified in
414 order, since
415 .B mhstore
416 will sort the partials, so that they are combined in the correct
417 order. But if
418 .B mhstore
419 can not locate every partial necessary to reassemble the message,
420 it will not store anything.
421 .SS "External Access"
422 For contents of type message/external-body,
423 \fImhstore\fR supports these access-types:
424 .IP \(bu 4
425 afs
426 .IP \(bu 4
427 anon-ftp
428 .IP \(bu 4
429 ftp
430 .IP \(bu 4
431 local-file
432 .IP \(bu 4
433 mail-server
434 .IP \(bu 4
435 url
436 .PP
437 For the \*(lqanon-ftp\*(rq and \*(lqftp\*(rq access types,
438 .B mhstore
439 will look for the \*(lqnmh-access-ftp\*(rq
440 profile entry, e.g.,
441 .PP
442 .RS 5
443 nmh-access-ftp: myftp.sh
444 .RE
445 .PP
446 to determine the pathname of a program to perform the FTP retrieval.
447 This program is invoked with these arguments:
448 .PP
449 .RS 5
450 .nf
451 domain name of FTP-site
452 username
453 password
454 remote directory
455 remote filename
456 local filename
457 \*(lqascii\*(rq or \*(lqbinary\*(rq
458 .fi
459 .RE
460 .PP
461 The program should terminate with an exit status of zero if the
462 retrieval is successful, and a non-zero exit status otherwise.
463 .PP
464 For the \*(lqurl\*(rq access types,
465 .B mhstore
466 will look for the \*(lqnmh-access-url\*(rq profile entry, e.g.,
467 .PP
468 .RS 5
469 nmh-access-url: curl -L
470 .RE
471 .PP
472 to determine the program to use to perform the HTTP retrieval. This program
473 is invoked with one argument: the URL of the content to retrieve. The program
474 should write the content to standard out, and should terminate with a status
475 of zero if the retrieval is successful and a non-zero exit status otherwise.
476 .SS "User Environment"
477 Because the environment in which
478 .B mhstore
479 operates may vary for different machines,
480 .B mhstore
481 will look for the environment variable MHSTORE .
482 If present, this specifies the name of an additional user profile
483 which should be read. Hence, when a user logs in on a particular
484 machine, this environment variable should be set to refer to a
485 file containing definitions useful for that machine. Finally,
486 .B mhstore
487 will attempt to consult
488 .PP
489 .RS 5
490 %nmhetcdir%/mhn.defaults
491 .RE
492 .PP
493 which is created automatically during
494 .B nmh
495 installation.
496 .PP
497 See "Profile Lookup" in
498 .IR mh-profile (5)
499 for the profile search order, and for how duplicate entries are treated.
500 .SH EXAMPLES
501 .SS Decoding RFC 2047-encoded file names
502 The improper RFC 2047 encoding of file name parameters can be replaced
503 with correct RFC 2231 encoding using
504 .BR mhfixmsg ,
505 either permanently or ephemerally, e.g.,
506 .PP
507 .RS
508 .nf
509 mhfixmsg -outfile - | mhstore -auto -clobber ask -file -
510 .fi
511 .RE
512 .PP
513 The
514 .BI \-clobber ask
515 is not necessary, though recommended to avoid silently overwriting an existing
516 file.
517 .SH FILES
518 .B mhstore
519 looks for additional profile files in multiple locations: absolute
520 pathnames are accessed directly, tilde expansion is done on usernames,
521 and files are searched for in the user's
522 .I Mail
523 directory as specified in their profile. If not found there, the directory
524 .RI \*(lq %nmhetcdir% \*(rq
525 is checked.
526 .PP
527 .fc ^ ~
528 .nf
529 .ta \w'%nmhetcdir%/ExtraBigFileName 'u
530 ^$HOME/.mh_profile~^The user profile
531 ^$MHSTORE~^Additional profile entries
532 ^%nmhetcdir%/mhn.defaults~^System default MIME profile entries
533 .fi
534 .SH "PROFILE COMPONENTS"
535 .fc ^ ~
536 .nf
537 .ta 2.4i
538 .ta \w'ExtraBigProfileName 'u
539 ^Path:~^To determine the user's nmh directory
540 ^Current\-Folder:~^To find the default current folder
541 ^nmh-access-ftp:~^Program to retrieve contents via FTP
542 ^nmh-access-url:~^Program to retrieve contents via HTTP
543 ^nmh-storage~^Directory to store contents
544 ^mhstore-store-<type>*~^Template for storing contents
545 .fi
546 .SH "SEE ALSO"
547 .IR mhbuild (1),
548 .IR mhfixmsg (1),
549 .IR mhlist (1),
550 .IR mhshow (1),
551 .IR sendfiles (1)
552 .SH DEFAULTS
553 .nf
554 .RB ` +folder "' defaults to the current folder"
555 .RB ` msgs "' defaults to cur"
556 .RB ` \-noauto '
557 .RB ` \-clobber\ always '
558 .RB ` \-nocheck '
559 .RB ` \-verbose '
560 .SH CONTEXT
561 If a folder is given, it will become the current folder. The last
562 message selected will become the current message.
563 .SH BUGS
564 Partial messages contained within a multipart content are not reassembled.