1 .TH MHFIXMSG %manext1% 2016-11-08 "%nmhversion%"
6 mhfixmsg \- rewrite nmh MIME messages with various transformations
15 .IR "absolute pathname" " | "
22 .IR "type/[subtype][,...]" ]
23 .RB [ \-crlflinebreaks " | " \-nocrlflinebreaks ]
26 .RB "| " \-notextcharset ]
27 .RB [ \-reformat " | " \-noreformat ]
28 .RB [ \-replacetextplain " | " \-noreplacetextplain ]
29 .RB [ \-fixboundary " | " \-nofixboundary ]
30 .RB [ \-fixcte " | " \-nofixcte ]
38 .RB [ \-changecur " | " \-nochangecur ]
39 .RB [ \-verbose " | " \-noverbose ]
43 rewrites MIME messages, applying specific transformations such as
44 decoding of MIME-encoded message parts and repairing invalid MIME
47 MIME messages are specified in RFC 2045 to RFC 2049
52 command is invaluable for viewing the content structure of MIME
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,
59 can safely be run multiple times on a message.
63 switch enables a transformation to decode each base64 and quoted-printable
64 text message part to the selected 8-bit, 7-bit, or
66 If 7-bit is selected for a base64 part but it will only fit
67 8-bit, as defined by RFC 2045, then it will be decoded to 8-bit
69 Similarly, with 8-bit, if the decoded text would be binary,
70 then the part is not decoded (and a message will be displayed if
72 is enabled). Note that
74 binary can produce messages that are not RFC 2045 compliant.
78 switch is enabled, each carriage return character that precedes a
79 linefeed character is removed from text parts encoded in ASCII,
80 ISO-8859-x, UTF-8, or Windows-12xx.
84 switch specifies the message parts, by type and optionally subtype,
87 applies. Its argument is a comma-separated list of type/subtype
88 elements. If an element does not contain a subtype, then
90 applies to all subtypes of the type. The default is
93 it can be overridden, e.g., with
98 to just text/plain parts.
100 By default, carriage return characters are preserved or inserted at
101 the end of each line of text content. The
103 switch selects this behavior and is enabled by default. The
104 .B \-nocrlflinebreaks
105 switch causes carriage return characters to be stripped from, and not
106 inserted in, text content when it is decoded and encoded. Note that
107 its use can cause the generation of MIME messages that do not conform
108 to RFC 2046, §4.1.1, paragraph 1.
112 switch specifies that all text/plain parts of the message(s)
113 should be converted to
115 Charset conversions require that
121 man page for how determine whether your
123 installation includes that.
124 To convert text parts other than text/plain, an external program can
131 switch enables a transformation for text parts in the message. For
132 each text part that is not text/plain and that does not have a
133 corresponding text/plain in a multipart/alternative part,
135 looks for a mhfixmsg-format-text/subtype profile entry that matches
136 the subtype of the part. If one is found and can be used to
137 successfully convert the part to text/plain,
139 inserts that text/plain part at the beginning of the containing
140 multipart/alternative part, if present. If not, it creates a
141 multipart/alternative part.
145 switch, multipart/related parts are handled differently than
146 multipart/alternative. If the multipart/related has only a single
147 part that is not text/plain and can be converted to text/plain, a
148 text/plain part is added and the type of the part is changed to
149 multipart/alternative. If the multipart/related has more than one
150 part but does not have a text/plain part,
155 .B \-replacetextplain
156 switch broadens the applicability of
158 by always replacing a corresponding text/plain part, if one exists.
161 is enabled, the replacement will be shown as two steps: a removal of
162 the text/plain part, followed by the usual insertion of a new part.
165 requires a profile entry for each text part subtype to be reformatted.
166 The mhfixmsg-format-text/subtype profile entries are based on external
167 conversion programs, and are used in the same way that
169 uses its mhshow-show-text/subtype entries. When
171 is installed, it searches for a conversion program for text/html
172 content, and if one is found, inserts a mhfixmsg-format-text/html
173 entry in %nmhetcdir%/mhn.defaults. An entry of the same name in the
174 user's profile takes precedence. The user can add entries for
175 other text subtypes to their profile.
179 switch enables a transformation to repair the boundary portion of the
180 Content-Type header field of the message to match the boundaries of
181 the outermost multipart part of the message, if it does not. That
182 condition is indicated by a \*(lqbogus multipart content in
183 message\*(rq error message from
187 programs that parse MIME messages.
191 switch enables a transformation to change the
192 Content-Transfer-Encoding from an invalid value to 8-bit in message
193 parts with a Content-Type of multipart and message, as required by
194 RFC 2045, §6.4. That condition is indicated by a \*(lqmust be
195 encoded in 7bit, 8bit, or binary\*(rq error message from
199 programs that parse MIME messages.
203 switch ensures that each part of the message has the correct MIME type
204 shown in its Content-Type header. It may be repeated. It is
205 typically used to replace \*(lqapplication/octet-stream\*(rq with a
206 more descriptive MIME type. It may not be used for multipart and
210 applies two transformations unconditionally.
211 The first removes an extraneous trailing semicolon from the parameter
212 lists of MIME header field values.
213 The second replaces RFC 2047 encoding with RFC 2231 encoding of name
214 and filename parameters in Content-Type and Content-Disposition header
215 field values, respectively.
221 to output informational message for each transformation applied.
225 is 0 if all of the requested transformations are performed, or
228 will not decode to binary content with the default
230 setting, but a request to do so is not considered a failure, and is noted
233 If a problem is detected with any one of multiple messages such that
234 the return status is non-zero, then none of the messages will be
242 to use the specified file as the source message, rather than a message
243 from a folder. Only one file argument may be provided. The
247 is an absolute pathname. If the file is \*(lq-\*(rq, then
249 accepts the source message on the standard input stream. If the
251 switch is not enabled when using the standard input stream,
253 will not produce a transformed output message.
256 by default, transforms the message in place. If the
258 switch is enabled, then
260 does not modify the input message or file, but instead places its
261 output in the specified file. An outfile name of \*(lq-\*(rq
262 specifies the standard output stream.
268 switch can be used to show what transformations
270 would apply without actually applying them, e.g.,
273 mhfixmsg -outfile /dev/null -verbose
276 As always, this usage obeys any
278 switches in the user's profile.
283 to add a single transformed message to a different folder, e.g.,
286 mhfixmsg -outfile - | \\
288 %nmhlibexecdir%/rcvstore +folder
291 .SS Summary of Applicability
292 The transformations apply to the parts of a message depending on
293 content type and/or encoding as follows:
297 .ta \w'\-crlflinebreaks 'u
298 \-decodetext base64 and quoted-printable encoded text parts
299 \-decodetypes limits parts to which -decodetext applies
300 \-crlflinebreaks text parts
301 \-textcharset text/plain parts
302 \-reformat text parts that are not text/plain
303 \-fixboundary outermost multipart part
304 \-fixcte multipart or message part
305 \-fixtype all except multipart and message parts
308 .SS "Backup of Original Message/File"
309 If it applies any transformations to a message or file, and the
313 backs up the original the same way as
317 profile component, if present. If not present,
319 moves the original message to a backup file.
322 switch may be used to override this profile component. The
324 switch disables the use of any
326 profile component and negates all prior
329 .SS "Integration with inc"
331 can be used as an add-hook, as described in %docdir%/README-HOOKS.
332 Note that add-hooks are called from all
334 programs that add a message to a folder, not just
336 Alternatively, a simple shell alias or function can be used to call
338 immediately after a successful invocation of
340 One approach could be based on:
343 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
344 mhfixmsg -nochangecur $msgs
347 Another approach would rely on adding a sequence to Unseen-Sequence,
350 sets with the newly incorporated messages. Those could then be
353 An example is shown below.
354 .SS "Integration with procmail"
355 By way of example, here is an excerpt from a procmailrc file
356 that filters messages through
358 before storing them in the user's
360 folder. It also stores the incoming message in the
362 folder in a filename generated by
364 which is a non-POSIX utility to generate a temporary file.
367 could be called on the message after it is stored.
371 .ta \w'\-fixboundary 'u
372 PATH = %bindir%:$PATH
374 MAILDIR = `mhparam path`
375 #### The Backups directory is relative to MAILDIR.
376 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
377 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
378 STORE = %nmhlibexecdir%/rcvstore
380 :0 w: nmh-workers/procmail.$LOCKEXT
381 * ^TOnmh-workers@nongnu.org
382 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
389 on the current message in the current folder, with default transformations to
390 fix MIME boundaries and Content-Transfer-Encoding, to decode text and
391 application/ics content parts to 8 bit, and to add a corresponding text/plain
399 .SS Specified folder and messages
402 on specified messages, without its informational output:
406 mhfixmsg +inbox last:4
409 .SS View without modification
412 transforms the message in place.
413 To view the MIME structure that would result from running
415 on the current message, without modifying the message:
419 mhfixmsg -outfile - | mhlist -file -
422 .SS Search message without modification
423 To search the current message, which possibly contains base64
424 or quoted printable encoded text parts, without modifying it,
431 mhfixmsg -outfile - | grep \fIpattern\fR
436 can be abbreviated in usual MH fashion, e.g., to -o. The search will be
437 on the entire message, not just text parts.
438 .SS Translate text/plain parts to UTF-8
439 To translate all text/plain parts in the current message to UTF-8, in addition
440 to all of the default transformations:
444 mhfixmsg -textcharset utf-8
447 .SS Fix all messages in a folder
450 on all of the messages in a folder:
460 can be run on each message separately, e.g., using a Bourne shell loop:
464 for msg in `pick +folder`; do mhfixmsg +folder $msg; done
468 The two appearances of the
470 switch in that command protect against concurrent context changes by other
473 .SS Run on newly incorporated messages
476 on messages as they are incorporated:
480 inc && mhfixmsg -nochangecur unseen
484 This assumes that the Unseen-Sequence profile entry is set to
490 looks for mhn.defaults in multiple locations: absolute pathnames are
491 accessed directly, tilde expansion is done on usernames, and files are
492 searched for in the user's
494 directory as specified in their profile. If not found there, the directory
495 .RI \*(lq %nmhetcdir% \*(rq
500 .ta \w'%nmhetcdir%/mhn.defaults 'u
501 ^$HOME/.mh_profile~^The user profile
502 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
504 .SH "PROFILE COMPONENTS"
508 .ta \w'ExtraBigProfileName 'u
509 ^Path:~^To determine the user's nmh directory
510 ^Current\-Folder:~^To find the default current folder
511 ^rmmproc:~^Program to delete original messages or files
528 .RB ` +folder "' defaults to the current folder"
529 .RB ` msgs "' defaults to cur"
530 .RB ` "\-decodetext 8bit"'
531 .RB ` "\-decodetypes text,application/ics"'
532 .RB ` \-crlflinebreaks '
533 .RB ` \-notextcharset '
535 .RB ` \-noreplacetextplain '
536 .RB ` \-fixboundary '
542 If a folder is given, it will become the current folder. The last
543 message selected from a folder will become the current message, unless
546 switch is enabled. If the
548 switch or an absolute pathname is used, the context will not be