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