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