1 .TH MHFIXMSG %manext1% "October 3, 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, 7bit, or
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
69 Similarly, with 8bit, if the decoded text would be binary,
70 then the part is not decoded (and a message will be
73 is enabled). Note that
75 binary can produce messages that are not RFC 2045 compliant.
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.
85 switch specifies the message parts, by type and optionally subtype,
88 applies. Its argument is a comma-separated list of type/subtype
89 elements. If an element does not contain a subtype, then
91 applies to all subtypes of the type. The default is
94 it can be overridden, e.g., with
99 to just text/plain parts.
101 By default, carriage return characters are preserved or inserted at
102 the end of each line of text content. The
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.
113 switch specifies that all text/plain parts of the message(s)
114 should be converted to
116 Charset conversions require that
122 man page for how determine whether your
124 installation includes that.
125 To convert text parts other than text/plain, an external program can
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,
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,
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.
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,
156 .B \-replacetextplain
157 switch broadens the applicability of
159 by always replacing a corresponding text/plain part, if one exists.
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.
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
170 uses its mhshow-show-text/subtype entries. When
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.
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
188 programs that parse MIME messages.
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
200 programs that parse MIME messages.
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
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.
222 to output informational message for each transformation applied.
226 is 0 if all of the requested transformations are performed, or
229 will not decode to binary content with the default
231 setting, but a request to do so is not considered a failure, and is noted
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
244 file as the source message, rather than a message from a folder.
245 Only one file argument may be provided. The
249 is an absolute pathname.
250 If the file is \*(lq-\*(rq, then
252 accepts the source message on the standard input stream. If
255 switch is not enabled when using the standard input stream,
257 will not produce a transformed output message.
260 by default, transforms the message in place. If the
262 switch is enabled, then
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.
272 switch can be used to show what transformations
274 would apply without actually applying them, e.g.,
277 mhfixmsg -outfile /dev/null -verbose
280 As always, this usage obeys any
282 switches in the user's profile.
287 to add a single transformed message to a different folder, e.g.,
290 mhfixmsg -outfile - | \\
292 %nmhlibexecdir%/rcvstore +folder
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:
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
312 .SS "Backup of Original Message/File"
313 If it applies any transformations to a message or file,
318 backs up the original the same way as
322 profile component, if present. If not present,
324 moves the original message to a backup file.
327 switch may be used to override this profile component. The
329 switch disables the use of any
331 profile component and negates all prior
334 .SS "Integration with inc"
336 can be used as an add-hook, as described in %docdir%/README-HOOKS.
337 Note that add-hooks are called from all
339 programs that add a message to a folder, not just
341 Alternatively, a simple shell alias or function can be used to
344 immediately after a successful invocation of
346 One approach could be based on:
349 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
350 mhfixmsg -nochangecur $msgs
353 Another approach would rely on adding a sequence to Unseen-Sequence,
356 sets with the newly incorporated messages. Those could then be
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
364 before storing them in the user's
366 folder. It also stores the incoming message in the
368 folder in a filename generated by
370 which is a non-POSIX utility to generate a temporary file.
373 could be called on the message after it is stored.
377 .ta \w'\-fixboundary 'u
378 PATH = %bindir%:$PATH
379 MAILDIR = `mhparam path`
380 #### The Backups directory is relative to MAILDIR.
381 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
382 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
383 STORE = %nmhlibexecdir%/rcvstore
385 :0 w: nmh-workers/procmail.$LOCKEXT
386 * ^TOnmh-workers@nongnu.org
387 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
395 on the current message in the current folder, with default transformations to
396 fix MIME boundaries and Content-Transfer-Encoding, to decode text and
397 application/ics content parts to 8 bit, and to add a corresponding text/plain
405 .SS Specified folder and messages
408 on specified messages, without its informational output:
412 mhfixmsg +inbox last:4
415 .SS View without modification
418 transforms the message in place. To view the MIME structure that would result from running
420 on the current message, without modifying the message:
424 mhfixmsg -outfile - | mhlist -file -
427 .SS Search message without modification
428 To search the current message, which possibly contains base64 or quoted printable encoded text parts,
429 without modifiying it, use the -outfile switch:
433 mhfixmsg -outfile - | grep \fIpattern\fR
437 -outfile can be abbreviated in usual MH fashion, e.g., to -o. The search will be
438 on the entire message, not just text parts.
439 .SS Translate text/plain parts to UTF-8
440 To translate all text/plain parts in the current message to UTF-8, in addition
441 to all of the default transformations:
445 mhfixmsg -textcharset utf-8
448 .SS Fix all messages in a folder
451 on all of the messages in a folder, using a Bourne shell loop:
455 for msg in `pick +folder`; do mhfixmsg $msg; done
460 can be run on more than one message, but on a large number of messages
461 may attempt to open too many files.
462 .SS Run on newly incorporated messages
465 on messages as they are incorporated:
469 inc && mhfixmsg -nochangecur unseen
473 This assumes that the Unseen-Sequence profile entry is set to
475 as shown in the mh\-profile(5) man page.
478 looks for mhn.defaults in multiple locations: absolute pathnames are
479 accessed directly, tilde expansion is done on usernames, and files are
480 searched for in the user's
482 directory as specified in their profile. If not found there, the directory
483 .RI \*(lq %nmhetcdir% \*(rq
488 .ta \w'%nmhetcdir%/mhn.defaults 'u
489 ^$HOME/\&.mh\(ruprofile~^The user profile
490 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
492 .SH "PROFILE COMPONENTS"
496 .ta \w'ExtraBigProfileName 'u
497 ^Path:~^To determine the user's nmh directory
498 ^Current\-Folder:~^To find the default current folder
499 ^rmmproc:~^Program to delete original messages or files
516 .RB ` +folder "' defaults to the current folder"
517 .RB ` msgs "' defaults to cur"
518 .RB ` "\-decodetext 8bit"'
519 .RB ` "\-decodetypes text,application/ics"'
520 .RB ` \-crlflinebreaks '
521 .RB ` \-notextcharset '
523 .RB ` \-noreplacetextplain '
524 .RB ` \-fixboundary '
530 If a folder is given, it will become the current folder. The last
531 message selected from a folder will become the current message, unless
534 switch is enabled. If the
536 switch or an absolute pathname is used, the context will not be
540 opens files internally for decoding and character set conversion, and apparently does not
541 close them expeditiously. Until that is resolved, it is recommended that
543 not be run on a large number of messages at once, as noted in the EXAMPLES above.