1 .TH MHFIXMSG %manext1% "March 12, 2016" "%nmhversion%"
6 mhfixmsg \- rewrite MIME messages with various transformations
13 .IR "absolute pathname" " | "
20 .IR "type/[subtype][,...]" ]
21 .RB [ \-crlflinebreaks " | " \-nocrlflinebreaks ]
24 .RB "| " \-notextcharset ]
25 .RB [ \-reformat " | " \-noreformat ]
26 .RB [ \-replacetextplain " | " \-noreplacetextplain ]
27 .RB [ \-fixboundary " | " \-nofixboundary ]
28 .RB [ \-fixcte " | " \-nofixcte ]
36 .RB [ \-changecur " | " \-nochangecur ]
37 .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
64 quoted-printable text message part to the selected 8bit or 7bit
65 encoding. If 7bit is selected for a base64 part but it will only fit
66 8bit, as defined by RFC 2045, then it will be decoded to 8bit
67 quoted-printable. Otherwise, if the decoded text would not fit the
68 selected encoding, the part is not decoded (and a message will be
75 switch is enabled, each carriage return character that precedes a
76 linefeed character is removed from text parts encoded in ASCII,
77 ISO-8859-x, UTF-8, or Windows-12xx.
81 switch specifies the message parts, by type and optionally subtype,
84 applies. Its argument is a comma-separated list of type/subtype
85 elements. If an element does not contain a subtype, then
87 applies to all subtypes of the type. The default is
90 it can be overridden, e.g., with
95 to just text/plain parts.
97 By default, carriage return characters are preserved or inserted at
98 the end of each line of text content. The
100 switch selects this behavior and is enabled by default. The
101 .B \-nocrlflinebreaks
102 switch causes carriage return characters to be stripped from, and not
103 inserted in, text content when it is decoded and encoded. Note that
104 its use can cause the generation of MIME messages that do not conform
105 with RFC 2046, §4.1.1, paragraph 1.
109 switch specifies that all text/plain parts of the message(s)
110 should be converted to
112 Charset conversions require that
118 man page for how determine whether your
120 installation includes that.
121 To convert text parts other than text/plain, an external program can
128 switch enables a transformation for text parts in the message. For
129 each text part that is not text/plain and that does not have a
130 corresponding text/plain in a multipart/alternative part,
132 looks for a mhfixmsg-format-text/subtype profile entry that matches
133 the subtype of the part. If one is found and can be used to
134 successfully convert the part to text/plain,
136 inserts that text/plain part at the beginning of the containing
137 multipart/alternative part, if present. If not, it creates a
138 multipart/alternative part.
142 switch, multipart/related parts are handled differently than
143 multipart/alternative. If the multipart/related has only a single
144 part that is not text/plain and can be converted to text/plain, a
145 text/plain part is added and the type of the part is changed to
146 multipart/alternative. If the multipart/related has more than one
147 part but does not have a text/plain part,
152 .B \-replacetextplain
153 switch broadens the applicability of
155 by always replacing a corresponding text/plain part, if one exists.
158 if enabled, the replacement will be shown as two steps: a removal of
159 the text/plain part followed by the usual insertion of a new part.
162 requires a profile entry for each text part subtype to be reformatted.
163 The mhfixmsg-format-text/subtype profile entries are based on external
164 conversion programs, and are used the same way that
166 uses its mhshow-show-text/subtype entries. When
168 is installed, it searches for a conversion program for text/html
169 content, and if one is found, inserts a mhfixmsg-format-text/html
170 entry in %nmhetcdir%/mhn.defaults. An entry of the same name in the
171 user's profile takes precedence. The user can add entries for
172 other text subtypes to their profile.
176 switch enables a transformation to repair the boundary portion of the
177 Content-Type header field of the message to match the boundaries of
178 the outermost multipart part of the message, if it does not. That
179 condition is indicated by a \*(lqbogus multipart content in
180 message\*(rq error message from
184 programs that parse MIME messages.
188 switch enables a transformation to change the
189 Content-Transfer-Encoding from an invalid value to 8bit in message
190 parts with a Content-Type of multipart, as required by RFC 2045,
191 §6.4. That condition is indicated by a \*(lqmust be encoded in
192 7bit, 8bit, or binary\*(rq error message from
196 programs that parse MIME messages.
200 switch ensures that each part of the message has the correct MIME type
201 shown in its Content-Type header. It may be repeated. It is
202 typically used to replace \*(lqapplication/octet-stream\*(rq with a
203 more descriptive MIME type. It may not be used for multipart and
207 applies one transformation unconditionally: it removes an extraneous
208 trailing semicolon from the parameter lists of MIME header fields.
214 to output informational message for each transformation applied.
218 is 0 if all of the requested transformations are performed, or
221 will not decode to binary content, but a request to do so is
222 not considered a failure, and is noted with
224 If a problem is detected with any one of multiple messages such that
225 the return status is non-zero, then none of the messages will be
234 file as the source message, rather than a message from a folder.
235 Only one file argument may be provided. The
239 is an absolute pathname.
240 If the file is \*(lq-\*(rq, then
242 accepts the source message on the standard input stream. If
245 switch is not enabled when using the standard input stream,
247 will not produce a transformed output message.
250 by default, transforms the message in place. If the
252 switch is enabled, then
254 does not modify the input message or file, but instead places its
255 output in the specified file. An outfile name of \*(lq-\*(rq
256 specifies the standard output stream.
262 switch can be used to show what transformations
264 would apply without actually applying them, e.g.,
267 mhfixmsg -outfile /dev/null -verbose
270 As always, this usage obeys any
272 switches in the user's profile.
277 to add a single transformed message to a different folder, e.g.,
280 mhfixmsg -outfile - | \\
282 %nmhlibexecdir%/rcvstore +folder
285 .SS Summary of Applicability
286 The transformations apply to the parts of a message depending on
287 content type and/or encoding as follows:
291 .ta \w'\-crlflinebreaks 'u
292 \-decodetext base64 and quoted-printable encoded text parts
293 \-decodetypes limits parts to which -decodetext applies
294 \-crlflinebreaks text parts
295 \-textcharset text/plain parts
296 \-reformat text parts that are not text/plain
297 \-fixboundary outermost multipart part
298 \-fixcte multipart part
299 \-fixtype all except multipart and message parts
302 .SS "Backup of Original Message/File"
303 If it applies any transformations to a message or file,
308 backs up the original the same way as
312 profile component, if present. If not present,
314 moves the original message to a backup file.
317 switch may be used to override this profile component. The
319 switch disables the use of any
321 profile component and negates all prior
324 .SS "Integration with inc"
326 can be used as an add-hook, as described in %docdir%/README-HOOKS.
327 Note that add-hooks are called from all
329 programs that add a message to a folder, not just
331 Alternatively, a simple shell alias or function can be used to
334 immediately after a successful invocation of
336 One approach could be based on:
339 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
340 mhfixmsg -nochangecur $msgs
343 Another approach would rely on adding a sequence to Unseen-Sequence,
346 sets with the newly incorporated messages. Those could then be
349 An example is shown below.
350 .SS "Integration with procmail"
351 By way of example, here is an excerpt from a procmailrc file
352 that filters messages through
354 before storing them in the user's
356 folder. It also stores the incoming message in the
358 folder in a filename generated by
360 which is a non-POSIX utility to generate a temporary file.
363 could be called on the message after it is stored.
367 .ta \w'\-fixboundary 'u
368 PATH = %bindir%:$PATH
369 MAILDIR = `mhparam path`
370 #### The Backups directory is relative to MAILDIR.
371 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
372 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
373 STORE = %nmhlibexecdir%/rcvstore
375 :0 w: nmh-workers/procmail.$LOCKEXT
376 * ^TOnmh-workers@nongnu.org
377 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
385 on the current message in the current folder, with default transformations to
386 fix MIME boundaries and Content-Transfer-Encoding, to decode text and
387 application/ics content parts to 8 bit, and to add a corresponding text/plain
395 .SS Specified folder and messages
398 on specified messages, without its informational output:
402 mhfixmsg +inbox last:4
405 .SS View without modification
408 transforms the message in place. To view the MIME structure that would result from running
410 on the current message, without modifying the message:
414 mhfixmsg -outfile - | mhlist -file -
417 .SS Search message without modification
418 To search the current message, which possibly contains base64 or quoted printable encoded text parts,
419 without modifiying it, use the -outfile switch:
423 mhfixmsg -outfile - | grep \fIpattern\fR
427 -outfile can be abbreviated in usual MH fashion, e.g., to -o. The search will be
428 on the entire message, not just text parts.
429 .SS Translate text/plain parts to UTF-8
430 To translate all text/plain parts in the current message to UTF-8, in addition
431 to all of the default transformations:
435 mhfixmsg -textcharset utf-8
438 .SS Fix all messages in a folder
441 on all of the messages in a folder, using a Bourne shell loop:
445 for msg in `pick +folder`; do mhfixmsg $msg; done
450 can be run on more than one message, but on a large number of messages
451 may attempt to open too many files.
452 .SS Run on newly incorporated messages
455 on messages as they are incorporated:
459 inc && mhfixmsg -nochangecur unseen
463 This assumes that the Unseen-Sequence profile entry is set to
465 as shown in the mh\-profile(5) man page.
468 looks for mhn.defaults in multiple locations: absolute pathnames are
469 accessed directly, tilde expansion is done on usernames, and files are
470 searched for in the user's
472 directory as specified in their profile. If not found there, the directory
473 .RI \*(lq %nmhetcdir% \*(rq
478 .ta \w'%nmhetcdir%/mhn.defaults 'u
479 ^$HOME/\&.mh\(ruprofile~^The user profile
480 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
482 .SH "PROFILE COMPONENTS"
486 .ta \w'ExtraBigProfileName 'u
487 ^Path:~^To determine the user's nmh directory
488 ^Current\-Folder:~^To find the default current folder
489 ^rmmproc:~^Program to delete original messages or files
506 .RB ` +folder "' defaults to the current folder"
507 .RB ` msgs "' defaults to cur"
508 .RB ` "\-decodetext 8bit"'
509 .RB ` "\-decodetypes text,application/ics"'
510 .RB ` \-crlflinebreaks '
511 .RB ` \-notextcharset '
513 .RB ` \-noreplacetextplain '
514 .RB ` \-fixboundary '
520 If a folder is given, it will become the current folder. The last
521 message selected from a folder will become the current message, unless
524 switch is enabled. If the
526 switch or an absolute pathname is used, the context will not be
530 opens files internally for decoding and character set conversion, and apparently does not
531 close them expeditiously. Until that is resolved, it is recommended that
533 not be run on a large number of messages at once, as noted in the EXAMPLES above.
535 As noted in the DESCRIPTION above,
537 will not decode to binary content. This restriction should be removed at some point. It's
538 not due to any issue in
540 but rather an observation of incorrect behavior by other nmh tools on messages with binary