1 .TH MHFIXMSG %manext1% "September 22, 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, as required by RFC 2045,
195 §6.4. That condition is indicated by a \*(lqmust be encoded in
196 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 one transformation unconditionally: it removes an extraneous
212 trailing semicolon from the parameter lists of MIME header fields.
218 to output informational message for each transformation applied.
222 is 0 if all of the requested transformations are performed, or
225 will not decode to binary content with the default
227 setting, but a request to do so is not considered a failure, and is noted
230 If a problem is detected with any one of multiple messages such that
231 the return status is non-zero, then none of the messages will be
240 file as the source message, rather than a message from a folder.
241 Only one file argument may be provided. The
245 is an absolute pathname.
246 If the file is \*(lq-\*(rq, then
248 accepts the source message on the standard input stream. If
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 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,
314 backs up the original the same way as
318 profile component, if present. If not present,
320 moves the original message to a backup file.
323 switch may be used to override this profile component. The
325 switch disables the use of any
327 profile component and negates all prior
330 .SS "Integration with inc"
332 can be used as an add-hook, as described in %docdir%/README-HOOKS.
333 Note that add-hooks are called from all
335 programs that add a message to a folder, not just
337 Alternatively, a simple shell alias or function can be used to
340 immediately after a successful invocation of
342 One approach could be based on:
345 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
346 mhfixmsg -nochangecur $msgs
349 Another approach would rely on adding a sequence to Unseen-Sequence,
352 sets with the newly incorporated messages. Those could then be
355 An example is shown below.
356 .SS "Integration with procmail"
357 By way of example, here is an excerpt from a procmailrc file
358 that filters messages through
360 before storing them in the user's
362 folder. It also stores the incoming message in the
364 folder in a filename generated by
366 which is a non-POSIX utility to generate a temporary file.
369 could be called on the message after it is stored.
373 .ta \w'\-fixboundary 'u
374 PATH = %bindir%:$PATH
375 MAILDIR = `mhparam path`
376 #### The Backups directory is relative to MAILDIR.
377 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
378 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
379 STORE = %nmhlibexecdir%/rcvstore
381 :0 w: nmh-workers/procmail.$LOCKEXT
382 * ^TOnmh-workers@nongnu.org
383 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
391 on the current message in the current folder, with default transformations to
392 fix MIME boundaries and Content-Transfer-Encoding, to decode text and
393 application/ics content parts to 8 bit, and to add a corresponding text/plain
401 .SS Specified folder and messages
404 on specified messages, without its informational output:
408 mhfixmsg +inbox last:4
411 .SS View without modification
414 transforms the message in place. To view the MIME structure that would result from running
416 on the current message, without modifying the message:
420 mhfixmsg -outfile - | mhlist -file -
423 .SS Search message without modification
424 To search the current message, which possibly contains base64 or quoted printable encoded text parts,
425 without modifiying it, use the -outfile switch:
429 mhfixmsg -outfile - | grep \fIpattern\fR
433 -outfile can be abbreviated in usual MH fashion, e.g., to -o. The search will be
434 on the entire message, not just text parts.
435 .SS Translate text/plain parts to UTF-8
436 To translate all text/plain parts in the current message to UTF-8, in addition
437 to all of the default transformations:
441 mhfixmsg -textcharset utf-8
444 .SS Fix all messages in a folder
447 on all of the messages in a folder, using a Bourne shell loop:
451 for msg in `pick +folder`; do mhfixmsg $msg; done
456 can be run on more than one message, but on a large number of messages
457 may attempt to open too many files.
458 .SS Run on newly incorporated messages
461 on messages as they are incorporated:
465 inc && mhfixmsg -nochangecur unseen
469 This assumes that the Unseen-Sequence profile entry is set to
471 as shown in the mh\-profile(5) man page.
474 looks for mhn.defaults in multiple locations: absolute pathnames are
475 accessed directly, tilde expansion is done on usernames, and files are
476 searched for in the user's
478 directory as specified in their profile. If not found there, the directory
479 .RI \*(lq %nmhetcdir% \*(rq
484 .ta \w'%nmhetcdir%/mhn.defaults 'u
485 ^$HOME/\&.mh\(ruprofile~^The user profile
486 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
488 .SH "PROFILE COMPONENTS"
492 .ta \w'ExtraBigProfileName 'u
493 ^Path:~^To determine the user's nmh directory
494 ^Current\-Folder:~^To find the default current folder
495 ^rmmproc:~^Program to delete original messages or files
512 .RB ` +folder "' defaults to the current folder"
513 .RB ` msgs "' defaults to cur"
514 .RB ` "\-decodetext 8bit"'
515 .RB ` "\-decodetypes text,application/ics"'
516 .RB ` \-crlflinebreaks '
517 .RB ` \-notextcharset '
519 .RB ` \-noreplacetextplain '
520 .RB ` \-fixboundary '
526 If a folder is given, it will become the current folder. The last
527 message selected from a folder will become the current message, unless
530 switch is enabled. If the
532 switch or an absolute pathname is used, the context will not be
536 opens files internally for decoding and character set conversion, and apparently does not
537 close them expeditiously. Until that is resolved, it is recommended that
539 not be run on a large number of messages at once, as noted in the EXAMPLES above.