]> diplodocus.org Git - nmh/blob - man/mhfixmsg.man
Separate out backquote expression to please Heirloom shell.
[nmh] / man / mhfixmsg.man
1 .TH MHFIXMSG %manext1% "November 7, 2016" "%nmhversion%"
2 .\"
3 .\" %nmhwarning%
4 .\"
5 .SH NAME
6 mhfixmsg \- rewrite MIME messages with various transformations
7 .SH SYNOPSIS
8 .HP 5
9 .na
10 .B mhfixmsg
11 .RB [ \-help ]
12 .RB [ \-version ]
13 .RI [ +folder ]
14 .RI [ msgs " | "
15 .IR "absolute pathname" " | "
16 .RB \-file
17 .IR file ]
18 .RB [ \-decodetext
19 8bit|7bit|binary |
20 .BR \-nodecodetext ]
21 .RB [ \-decodetypes
22 .IR "type/[subtype][,...]" ]
23 .RB [ \-crlflinebreaks " | " \-nocrlflinebreaks ]
24 .RB [ \-textcharset
25 .I charset
26 .RB "| " \-notextcharset ]
27 .RB [ \-reformat " | " \-noreformat ]
28 .RB [ \-replacetextplain " | " \-noreplacetextplain ]
29 .RB [ \-fixboundary " | " \-nofixboundary ]
30 .RB [ \-fixcte " | " \-nofixcte ]
31 .RB [ \-fixtype
32 .IR mimetype ]
33 .RB [ \-outfile
34 .IR outfile ]
35 .RB [ \-rmmproc
36 .IR program ]
37 .RB [ \-normmproc ]
38 .RB [ \-changecur " | " \-nochangecur ]
39 .RB [ \-verbose " | " \-noverbose ]
40 .ad
41 .SH DESCRIPTION
42 .B mhfixmsg
43 rewrites MIME messages, applying specific transformations such as
44 decoding of MIME-encoded message parts and repairing invalid MIME
45 headers.
46 .PP
47 MIME messages are specified in RFC 2045 to RFC 2049
48 (see
49 .IR mhbuild (1)).
50 The
51 .B mhlist
52 command is invaluable for viewing the content structure of MIME
53 messages.
54 .B mhfixmsg
55 passes non-MIME messages through without any transformations. If no
56 transformations apply to a MIME message, the original message or file
57 is not modified or removed. Thus,
58 .B mhfixmsg
59 can safely be run multiple times on a message.
60 .PP
61 The
62 .B \-decodetext
63 switch enables a transformation to decode each base64 and
64 quoted-printable text message part to the selected 8bit, 7bit, or
65 binary encoding.
66 If 7bit is selected for a base64 part but it will only fit
67 8bit, as defined by RFC 2045, then it will be decoded to 8bit
68 quoted-printable.
69 Similarly, with 8bit, if the decoded text would be binary,
70 then the part is not decoded (and a message will be
71 displayed if
72 .B \-verbose
73 is enabled). Note that
74 .B \-decodetext
75 binary can produce messages that are not RFC 2045 compliant.
76 .PP
77 When the
78 .B \-decodetext
79 switch is enabled, each carriage return character that precedes a
80 linefeed character is removed from text parts encoded in ASCII,
81 ISO-8859-x, UTF-8, or Windows-12xx.
82 .PP
83 The
84 .B \-decodetypes
85 switch specifies the message parts, by type and optionally subtype,
86 to which
87 .B \-decodetext
88 applies. Its argument is a comma-separated list of type/subtype
89 elements. If an element does not contain a subtype, then
90 .B \-decodetext
91 applies to all subtypes of the type. The default is
92 .B \-decodetypes
93 .IR text ;
94 it can be overridden, e.g., with
95 .B \-decodetypes
96 .I text/plain
97 to restrict
98 .B \-decodetext
99 to just text/plain parts.
100 .PP
101 By default, carriage return characters are preserved or inserted at
102 the end of each line of text content. The
103 .B \-crlflinebreaks
104 switch selects this behavior and is enabled by default. The
105 .B \-nocrlflinebreaks
106 switch causes carriage return characters to be stripped from, and not
107 inserted in, text content when it is decoded and encoded. Note that
108 its use can cause the generation of MIME messages that do not conform
109 with RFC 2046, §4.1.1, paragraph 1.
110 .PP
111 The
112 .B \-textcharset
113 switch specifies that all text/plain parts of the message(s)
114 should be converted to
115 .IR charset .
116 Charset conversions require that
117 .B nmh
118 be built with
119 .IR iconv (3);
120 see the
121 .BR mhparam (1)
122 man page for how determine whether your
123 .B nmh
124 installation includes that.
125 To convert text parts other than text/plain, an external program can
126 be used, via the
127 .B \-reformat
128 switch.
129 .PP
130 The
131 .B \-reformat
132 switch enables a transformation for text parts in the message. For
133 each text part that is not text/plain and that does not have a
134 corresponding text/plain in a multipart/alternative part,
135 .B mhfixmsg
136 looks for a mhfixmsg-format-text/subtype profile entry that matches
137 the subtype of the part. If one is found and can be used to
138 successfully convert the part to text/plain,
139 .B mhfixmsg
140 inserts that text/plain part at the beginning of the containing
141 multipart/alternative part, if present. If not, it creates a
142 multipart/alternative part.
143 .PP
144 With the
145 .B \-reformat
146 switch, multipart/related parts are handled differently than
147 multipart/alternative. If the multipart/related has only a single
148 part that is not text/plain and can be converted to text/plain, a
149 text/plain part is added and the type of the part is changed to
150 multipart/alternative. If the multipart/related has more than one
151 part but does not have a text/plain part,
152 .B mhfixmsg
153 tries to add one.
154 .PP
155 The
156 .B \-replacetextplain
157 switch broadens the applicability of
158 .B \-reformat
159 by always replacing a corresponding text/plain part, if one exists.
160 If
161 .B \-verbose
162 if enabled, the replacement will be shown as two steps: a removal of
163 the text/plain part followed by the usual insertion of a new part.
164 .PP
165 .B \-reformat
166 requires a profile entry for each text part subtype to be reformatted.
167 The mhfixmsg-format-text/subtype profile entries are based on external
168 conversion programs, and are used the same way that
169 .B mhshow
170 uses its mhshow-show-text/subtype entries. When
171 .B nmh
172 is installed, it searches for a conversion program for text/html
173 content, and if one is found, inserts a mhfixmsg-format-text/html
174 entry in %nmhetcdir%/mhn.defaults. An entry of the same name in the
175 user's profile takes precedence. The user can add entries for
176 other text subtypes to their profile.
177 .PP
178 The
179 .B \-fixboundary
180 switch enables a transformation to repair the boundary portion of the
181 Content-Type header field of the message to match the boundaries of
182 the outermost multipart part of the message, if it does not. That
183 condition is indicated by a \*(lqbogus multipart content in
184 message\*(rq error message from
185 .B mhlist
186 and other
187 .B nmh
188 programs that parse MIME messages.
189 .PP
190 The
191 .B \-fixcte
192 switch enables a transformation to change the
193 Content-Transfer-Encoding from an invalid value to 8bit in message
194 parts with a Content-Type of multipart and message, as required by
195 RFC 2045, §6.4. That condition is indicated by a \*(lqmust be
196 encoded in 7bit, 8bit, or binary\*(rq error message from
197 .B mhlist
198 and other
199 .B nmh
200 programs that parse MIME messages.
201 .PP
202 The
203 .B \-fixtype
204 switch ensures that each part of the message has the correct MIME type
205 shown in its Content-Type header. It may be repeated. It is
206 typically used to replace \*(lqapplication/octet-stream\*(rq with a
207 more descriptive MIME type. It may not be used for multipart and
208 message types.
209 .PP
210 .B mhfixmsg
211 applies two transformations unconditionally.
212 The first removes an extraneous trailing semicolon from the parameter
213 lists of MIME header field values.
214 The second replaces RFC 2047 encoding with RFC 2231 encoding of name
215 and filename parameters in Content-Type and Content-Disposition header
216 field values, respectively.
217 .PP
218 The
219 .B \-verbose
220 switch directs
221 .B mhfixmsg
222 to output informational message for each transformation applied.
223 .PP
224 The return status of
225 .B mhfixmsg
226 is 0 if all of the requested transformations are performed, or
227 non-zero otherwise.
228 .RB ( mhfixmsg
229 will not decode to binary content with the default
230 .B \-decodetext
231 setting, but a request to do so is not considered a failure, and is noted
232 with
233 .BR \-verbose .)
234 If a problem is detected with any one of multiple messages such that
235 the return status is non-zero, then none of the messages will be
236 modified.
237 .PP
238 The
239 .B \-file
240 .I file
241 switch directs
242 .B mhfixmsg
243 to use the specified
244 file as the source message, rather than a message from a folder.
245 Only one file argument may be provided. The
246 .B \-file
247 switch is implied if
248 .I file
249 is an absolute pathname.
250 If the file is \*(lq-\*(rq, then
251 .B mhfixmsg
252 accepts the source message on the standard input stream. If
253 the
254 .B \-outfile
255 switch is not enabled when using the standard input stream,
256 .B mhfixmsg
257 will not produce a transformed output message.
258 .PP
259 .BR mhfixmsg ,
260 by default, transforms the message in place. If the
261 .B \-outfile
262 switch is enabled, then
263 .B mhfixmsg
264 does not modify the input message or file, but instead places its
265 output in the specified file. An outfile name of \*(lq-\*(rq
266 specifies the standard output stream.
267 .PP
268 Combined with the
269 .B \-verbose
270 switch, the
271 .B \-outfile
272 switch can be used to show what transformations
273 .B mhfixmsg
274 would apply without actually applying them, e.g.,
275 .PP
276 .RS 5
277 mhfixmsg -outfile /dev/null -verbose
278 .RE
279 .PP
280 As always, this usage obeys any
281 .B mhfixmsg
282 switches in the user's profile.
283 .PP
284 .B \-outfile
285 can be combined with
286 .B rcvstore
287 to add a single transformed message to a different folder, e.g.,
288 .PP
289 .RS 5
290 mhfixmsg -outfile - | \\
291 .RS 0
292 %nmhlibexecdir%/rcvstore +folder
293 .RE
294 .RE
295 .SS Summary of Applicability
296 The transformations apply to the parts of a message depending on
297 content type and/or encoding as follows:
298 .PP
299 .RS 5
300 .nf
301 .ta \w'\-crlflinebreaks 'u
302 \-decodetext base64 and quoted-printable encoded text parts
303 \-decodetypes limits parts to which -decodetext applies
304 \-crlflinebreaks text parts
305 \-textcharset text/plain parts
306 \-reformat text parts that are not text/plain
307 \-fixboundary outermost multipart part
308 \-fixcte multipart or message part
309 \-fixtype all except multipart and message parts
310 .fi
311 .RE
312 .SS "Backup of Original Message/File"
313 If it applies any transformations to a message or file,
314 and the
315 .B \-outfile
316 switch is not used,
317 .B mhfixmsg
318 backs up the original the same way as
319 .BR rmm .
320 That is, it uses the
321 .I rmmproc
322 profile component, if present. If not present,
323 .B mhfixmsg
324 moves the original message to a backup file.
325 The
326 .B \-rmmproc
327 switch may be used to override this profile component. The
328 .B \-normmproc
329 switch disables the use of any
330 .I rmmproc
331 profile component and negates all prior
332 .B \-rmmproc
333 switches.
334 .SS "Integration with inc"
335 .B mhfixmsg
336 can be used as an add-hook, as described in %docdir%/README-HOOKS.
337 Note that add-hooks are called from all
338 .B nmh
339 programs that add a message to a folder, not just
340 .BR inc .
341 Alternatively, a simple shell alias or function can be used to
342 call
343 .B mhfixmsg
344 immediately after a successful invocation of
345 .BR inc .
346 One approach could be based on:
347 .PP
348 .RS 5
349 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
350 mhfixmsg -nochangecur $msgs
351 .RE
352 .PP
353 Another approach would rely on adding a sequence to Unseen-Sequence,
354 which
355 .B inc
356 sets with the newly incorporated messages. Those could then be
357 supplied to
358 .BR mhfixmsg .
359 An example is shown below.
360 .SS "Integration with procmail"
361 By way of example, here is an excerpt from a procmailrc file
362 that filters messages through
363 .B mhfixmsg
364 before storing them in the user's
365 .I nmh-workers
366 folder. It also stores the incoming message in the
367 .I Backups
368 folder in a filename generated by
369 .BR mkstemp ,
370 which is a non-POSIX utility to generate a temporary file.
371 Alternatively,
372 .B mhfixmsg
373 could be called on the message after it is stored.
374 .PP
375 .RS 5
376 .nf
377 .ta \w'\-fixboundary 'u
378 PATH = %bindir%:$PATH
379 LANG = en_US.utf8
380 MAILDIR = `mhparam path`
381 #### The Backups directory is relative to MAILDIR.
382 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
383 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
384 STORE = %nmhlibexecdir%/rcvstore
385
386 :0 w: nmh-workers/procmail.$LOCKEXT
387 * ^TOnmh-workers@nongnu.org
388 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
389 .fi
390 .RE
391 .SH "EXAMPLES"
392 .PP
393 .SS Basic usage
394 To run
395 .B mhfixmsg
396 on the current message in the current folder, with default transformations to
397 fix MIME boundaries and Content-Transfer-Encoding, to decode text and
398 application/ics content parts to 8 bit, and to add a corresponding text/plain
399 part where lacking:
400 .PP
401 .RS
402 .nf
403 mhfixmsg -verbose
404 .fi
405 .RE
406 .SS Specified folder and messages
407 To run
408 .B mhfixmsg
409 on specified messages, without its informational output:
410 .PP
411 .RS
412 .nf
413 mhfixmsg +inbox last:4
414 .fi
415 .RE
416 .SS View without modification
417 By default,
418 .B mhfixmsg
419 transforms the message in place. To view the MIME structure that would result from running
420 .B mhfixmsg
421 on the current message, without modifying the message:
422 .PP
423 .RS
424 .nf
425 mhfixmsg -outfile - | mhlist -file -
426 .fi
427 .RE
428 .SS Search message without modification
429 To search the current message, which possibly contains base64 or quoted printable encoded text parts,
430 without modifying it, use the -outfile switch:
431 .PP
432 .RS
433 .nf
434 mhfixmsg -outfile - | grep \fIpattern\fR
435 .fi
436 .RE
437 .PP
438 -outfile can be abbreviated in usual MH fashion, e.g., to -o. The search will be
439 on the entire message, not just text parts.
440 .SS Translate text/plain parts to UTF-8
441 To translate all text/plain parts in the current message to UTF-8, in addition
442 to all of the default transformations:
443 .PP
444 .RS
445 .nf
446 mhfixmsg -textcharset utf-8
447 .fi
448 .RE
449 .SS Fix all messages in a folder
450 To run
451 .B mhfixmsg
452 on all of the messages in a folder:
453 .PP
454 .RS
455 .nf
456 mhfixmsg +folder all
457 .fi
458 .RE
459 .PP
460 Alternatively,
461 .B mhfixmsg
462 can be run on each message separately, e.g., using a Bourne shell loop:
463 .PP
464 .RS
465 .nf
466 for msg in `pick +folder`; do mhfixmsg +folder $msg; done
467 .fi
468 .RE
469 .PP
470 The two appearances of the
471 .B +folder
472 switch in that command protect against concurrent context changes by other
473 .B nmh
474 command invocations.
475 .SS Run on newly incorporated messages
476 To run
477 .B mhfixmsg
478 on messages as they are incorporated:
479 .PP
480 .RS
481 .nf
482 inc && mhfixmsg -nochangecur unseen
483 .fi
484 .RE
485 .PP
486 This assumes that the Unseen-Sequence profile entry is set to
487 .BR unseen ,
488 as shown in the mh\-profile(5) man page.
489 .SH FILES
490 .B mhfixmsg
491 looks for mhn.defaults in multiple locations: absolute pathnames are
492 accessed directly, tilde expansion is done on usernames, and files are
493 searched for in the user's
494 .I Mail
495 directory as specified in their profile. If not found there, the directory
496 .RI \*(lq %nmhetcdir% \*(rq
497 is checked.
498 .PP
499 .fc ^ ~
500 .nf
501 .ta \w'%nmhetcdir%/mhn.defaults 'u
502 ^$HOME/\&.mh\(ruprofile~^The user profile
503 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
504 .fi
505 .SH "PROFILE COMPONENTS"
506 .fc ^ ~
507 .nf
508 .ta 2.4i
509 .ta \w'ExtraBigProfileName 'u
510 ^Path:~^To determine the user's nmh directory
511 ^Current\-Folder:~^To find the default current folder
512 ^rmmproc:~^Program to delete original messages or files
513 .fi
514 .SH "SEE ALSO"
515 .IR inc (1),
516 .IR iconv (3),
517 .IR mh-profile (5),
518 .IR mhbuild (1),
519 .IR mhlist (1),
520 .IR mhparam (1),
521 .IR mhshow (1),
522 .IR mh-mkstemp (1),
523 .IR procmail (1),
524 .IR procmailrc (5),
525 .IR rcvstore (1),
526 .IR rmm (1)
527 .SH DEFAULTS
528 .nf
529 .RB ` +folder "' defaults to the current folder"
530 .RB ` msgs "' defaults to cur"
531 .RB ` "\-decodetext 8bit"'
532 .RB ` "\-decodetypes text,application/ics"'
533 .RB ` \-crlflinebreaks '
534 .RB ` \-notextcharset '
535 .RB ` \-reformat '
536 .RB ` \-noreplacetextplain '
537 .RB ` \-fixboundary '
538 .RB ` \-fixcte '
539 .RB ` \-changecur '
540 .RB ` \-noverbose '
541 .fi
542 .SH CONTEXT
543 If a folder is given, it will become the current folder. The last
544 message selected from a folder will become the current message, unless
545 the
546 .B \-nochangecur
547 switch is enabled. If the
548 .B \-file
549 switch or an absolute pathname is used, the context will not be
550 modified.