1MHFIXMSG(1) General Commands Manual MHFIXMSG(1)
2
3
4
6 mhfixmsg - nmh's MIME-email rewriter with various transformations
7
9 mhfixmsg [-help] [-version] [+folder] [msgs | absolute pathname | -file
10 file] [-decodetext 8bit|7bit|binary | -nodecodetext] [-decodetypes
11 type/[subtype][,...]] [-crlflinebreaks | -nocrlflinebreaks]
12 [-textcharset charset | -notextcharset] [-reformat | -noreformat]
13 [-replacetextplain | -noreplacetextplain] [-fixboundary |
14 -nofixboundary] [-fixcte | -nofixcte] [-fixtype mimetype] [-out‐
15 file outfile] [-rmmproc program] [-normmproc] [-changecur |
16 -nochangecur] [-verbose | -noverbose]
17
19 mhfixmsg rewrites MIME messages, applying specific transformations such
20 as decoding of MIME-encoded message parts and repairing invalid MIME
21 headers.
22
23 MIME messages are specified in RFC 2045 to RFC 2049 (see mhbuild(1)).
24 The mhlist command is invaluable for viewing the content structure of
25 MIME messages. mhfixmsg passes non-MIME messages through without any
26 transformations. If no transformations apply to a MIME message, the
27 original message or file is not modified or removed. Thus, mhfixmsg
28 can safely be run multiple times on a message.
29
30 The -decodetext switch enables a transformation to decode each base64
31 and quoted-printable text message part to the selected 8-bit, 7-bit, or
32 binary encoding. If 7-bit is selected for a base64 part but it will
33 only fit 8-bit, as defined by RFC 2045, then it will be decoded to
34 8-bit quoted-printable. Similarly, with 8-bit, if the decoded text
35 would be binary, then the part is not decoded (and a message will be
36 displayed if -verbose is enabled). Note that -decodetext binary can
37 produce messages that are not RFC 2045 compliant.
38
39 When the -decodetext switch is enabled, each carriage return character
40 that precedes a linefeed character is removed from text parts encoded
41 in ASCII, ISO-8859-x, UTF-8, or Windows-12xx.
42
43 The -decodetypes switch specifies the message parts, by type and
44 optionally subtype, to which -decodetext applies. Its argument is a
45 comma-separated list of type/subtype elements. If an element does not
46 contain a subtype, then -decodetext applies to all subtypes of the
47 type. The default is -decodetypes text; it can be overridden, e.g.,
48 with -decodetypes text/plain to restrict -decodetext to just text/plain
49 parts.
50
51 By default, carriage return characters are preserved or inserted at the
52 end of each line of text content. The -crlflinebreaks switch selects
53 this behavior and is enabled by default. The -nocrlflinebreaks switch
54 causes carriage return characters to be stripped from, and not inserted
55 in, text content when it is decoded and encoded. Note that its use can
56 cause the generation of MIME messages that do not conform to RFC 2046,
57 §4.1.1, paragraph 1.
58
59 The -textcharset switch specifies that all text/plain parts of the mes‐
60 sage(s) should be converted to charset. Charset conversions require
61 that nmh be built with iconv(3); see the mhparam(1) man page for how
62 determine whether your nmh installation includes that. To convert text
63 parts other than text/plain, an external program can be used, via the
64 -reformat switch.
65
66 The -reformat switch enables a transformation for text parts in the
67 message. For each text part that is not text/plain and that does not
68 have a corresponding text/plain in a multipart/alternative part,
69 mhfixmsg looks for a mhfixmsg-format-text/subtype profile entry that
70 matches the subtype of the part. If one is found and can be used to
71 successfully convert the part to text/plain, mhfixmsg inserts that
72 text/plain part at the beginning of the containing multipart/alterna‐
73 tive part, if present. If not, it creates a multipart/alternative
74 part.
75
76 With the -reformat switch, multipart/related parts are handled differ‐
77 ently than multipart/alternative. If the multipart/related has only a
78 single part that is not text/plain and can be converted to text/plain,
79 a text/plain part is added and the type of the part is changed to mul‐
80 tipart/alternative. If the multipart/related has more than one part
81 but does not have a text/plain part, mhfixmsg tries to add one.
82
83 The -replacetextplain switch broadens the applicability of -reformat,
84 by always replacing a corresponding text/plain part, if one exists. If
85 -verbose is enabled, the replacement will be shown as two steps: a
86 removal of the text/plain part, followed by the usual insertion of a
87 new part.
88
89 -reformat requires a profile entry for each text part subtype to be
90 reformatted. The mhfixmsg-format-text/subtype profile entries are
91 based on external conversion programs, and are used in the same way
92 that mhshow uses its mhshow-show-text/subtype entries. When nmh is
93 installed, it searches for a conversion program for text/html content,
94 and if one is found, inserts a mhfixmsg-format-text/html entry in
95 /etc/nmh/mhn.defaults. An entry of the same name in the user's profile
96 takes precedence. The user can add entries for other text subtypes to
97 their profile.
98
99 The -fixboundary switch enables a transformation to repair the boundary
100 portion of the Content-Type header field of the message to match the
101 boundaries of the outermost multipart part of the message, if it does
102 not. That condition is indicated by a “bogus multipart content in mes‐
103 sage” error message from mhlist and other nmh programs that parse MIME
104 messages.
105
106 The -fixcte switch enables a transformation to change the Content-
107 Transfer-Encoding from an invalid value to 8-bit in message parts with
108 a Content-Type of multipart and message, as required by RFC 2045, §6.4.
109 That condition is indicated by a “must be encoded in 7bit, 8bit, or
110 binary” error message from mhlist and other nmh programs that parse
111 MIME messages.
112
113 The -fixtype switch ensures that each part of the message has the cor‐
114 rect MIME type shown in its Content-Type header. It may be repeated.
115 It is typically used to replace “application/octet-stream” with a more
116 descriptive MIME type. It may not be used for multipart and message
117 types.
118
119 mhfixmsg applies two transformations unconditionally. The first
120 removes an extraneous trailing semicolon from the parameter lists of
121 MIME header field values. The second replaces RFC 2047 encoding with
122 RFC 2231 encoding of name and filename parameters in Content-Type and
123 Content-Disposition header field values, respectively.
124
125 The -verbose switch directs mhfixmsg to output informational message
126 for each transformation applied.
127
128 The return status of mhfixmsg is 0 if all of the requested transforma‐
129 tions are performed, or non-zero otherwise. (mhfixmsg will not decode
130 to binary content with the default -decodetext setting, but a request
131 to do so is not considered a failure, and is noted with -verbose.) If
132 a problem is detected with any one of multiple messages such that the
133 return status is non-zero, then none of the messages will be modified.
134
135 The -file file switch directs mhfixmsg to use the specified file as the
136 source message, rather than a message from a folder. Only one file
137 argument may be provided. The -file switch is implied if file is an
138 absolute pathname. If the file is “-”, then mhfixmsg accepts the
139 source message on the standard input stream. If the -outfile switch is
140 not enabled when using the standard input stream, mhfixmsg will not
141 produce a transformed output message.
142
143 mhfixmsg, by default, transforms the message in place. If the -outfile
144 switch is enabled, then mhfixmsg does not modify the input message or
145 file, but instead places its output in the specified file. An outfile
146 name of “-” specifies the standard output stream.
147
148 Combined with the -verbose switch, the -outfile switch can be used to
149 show what transformations mhfixmsg would apply without actually apply‐
150 ing them, e.g.,
151
152 mhfixmsg -outfile /dev/null -verbose
153
154 As always, this usage obeys any mhfixmsg switches in the user's pro‐
155 file.
156
157 -outfile can be combined with rcvstore to add a single transformed mes‐
158 sage to a different folder, e.g.,
159
160 mhfixmsg -outfile - | \
161 /usr/libexec/nmh/rcvstore +folder
162
163 Summary of Applicability
164 The transformations apply to the parts of a message depending on con‐
165 tent type and/or encoding as follows:
166
167 -decodetext base64 and quoted-printable encoded text parts
168 -decodetypes limits parts to which -decodetext applies
169 -crlflinebreaks text parts
170 -textcharset text/plain parts
171 -reformat text parts that are not text/plain
172 -fixboundary outermost multipart part
173 -fixcte multipart or message part
174 -fixtype all except multipart and message parts
175
176 Backup of Original Message/File
177 If it applies any transformations to a message or file, and the -out‐
178 file switch is not used, mhfixmsg backs up the original the same way as
179 rmm. That is, it uses the rmmproc profile component, if present. If
180 not present, mhfixmsg moves the original message to a backup file. The
181 -rmmproc switch may be used to override this profile component. The
182 -normmproc switch disables the use of any rmmproc profile component and
183 negates all prior -rmmproc switches.
184
185 Integration with inc
186 mhfixmsg can be used as an add-hook, as described in
187 /usr/share/doc/nmh/README-HOOKS. Note that add-hooks are called from
188 all nmh programs that add a message to a folder, not just inc. Alter‐
189 natively, a simple shell alias or function can be used to call mhfixmsg
190 immediately after a successful invocation of inc. One approach could
191 be based on:
192
193 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs
194 && mhfixmsg -nochangecur $msgs
195
196 Another approach would rely on adding a sequence to Unseen-Sequence,
197 which inc sets with the newly incorporated messages. Those could then
198 be supplied to mhfixmsg. An example is shown below.
199
200 Integration with procmail
201 By way of example, here is an excerpt from a procmailrc file that fil‐
202 ters messages through mhfixmsg before storing them in the user's nmh-
203 workers folder. It also stores the incoming message in the Backups
204 folder in a filename generated by mkstemp, which is a non-POSIX utility
205 to generate a temporary file. Alternatively, mhfixmsg could be called
206 on the message after it is stored.
207
208 PATH = /usr/bin:$PATH
209 LANG = en_US.utf8
210 MAILDIR = `mhparam path`
211 #### The Backups directory is relative to MAILDIR.
212 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
213 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
214 STORE = /usr/libexec/nmh/rcvstore
215
216 :0 w: nmh-workers/procmail.$LOCKEXT
217 * ^TOnmh-workers@nongnu.org
218 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
219
221 Basic usage
222 To run mhfixmsg on the current message in the current folder, with
223 default transformations to fix MIME boundaries and Content-Transfer-
224 Encoding, to decode text and application/ics content parts to 8 bit,
225 and to add a corresponding text/plain part where lacking:
226
227 mhfixmsg -verbose
228
229 Specified folder and messages
230 To run mhfixmsg on specified messages, without its informational out‐
231 put:
232
233 mhfixmsg +inbox last:4
234
235 View without modification
236 By default, mhfixmsg transforms the message in place. To view the MIME
237 structure that would result from running mhfixmsg on the current mes‐
238 sage, without modifying the message:
239
240 mhfixmsg -outfile - | mhlist -file -
241
242 Search message without modification
243 To search the current message, which possibly contains base64 or quoted
244 printable encoded text parts, without modifying it, use the -outfile
245 switch:
246
247 mhfixmsg -outfile - | grep pattern
248
249 -outfile can be abbreviated in usual MH fashion, e.g., to -o. The
250 search will be on the entire message, not just text parts.
251
252 Translate text/plain parts to UTF-8
253 To translate all text/plain parts in the current message to UTF-8, in
254 addition to all of the default transformations:
255
256 mhfixmsg -textcharset utf-8
257
258 Fix all messages in a folder
259 To run mhfixmsg on all of the messages in a folder:
260
261 mhfixmsg +folder all
262
263 Alternatively, mhfixmsg can be run on each message separately, e.g.,
264 using a Bourne shell loop:
265
266 for msg in `pick +folder`; do mhfixmsg +folder $msg; done
267
268 The two appearances of the +folder switch in that command protect
269 against concurrent context changes by other nmh command invocations.
270
271 Run on newly incorporated messages
272 To run mhfixmsg on messages as they are incorporated:
273
274 inc && mhfixmsg -nochangecur unseen
275
276 This assumes that the Unseen-Sequence profile entry is set to unseen,
277 as shown in mh-profile(5).
278
280 mhfixmsg looks for mhn.defaults in multiple locations: absolute path‐
281 names are accessed directly, tilde expansion is done on usernames, and
282 files are searched for in the user's Mail directory as specified in
283 their profile. If not found there, the directory “/etc/nmh” is
284 checked.
285
286 $HOME/.mh_profile The user profile
287 /etc/nmh/mhn.defaults Default mhfixmsg conversion entries
288
290 Path: To determine the user's nmh directory
291 Current-Folder: To find the default current folder
292 rmmproc: Program to delete original messages or files
293
295 iconv(3), inc(1), mh-mkstemp(1), mh-profile(5), mhbuild(1), mhlist(1),
296 mhparam(1), mhshow(1), procmail(1), procmailrc(5), rcvstore(1), rmm(1)
297
299 `+folder' defaults to the current folder
300 `msgs' defaults to cur
301 `-decodetext 8bit'
302 `-decodetypes text,application/ics'
303 `-crlflinebreaks'
304 `-notextcharset'
305 `-reformat'
306 `-noreplacetextplain'
307 `-fixboundary'
308 `-fixcte'
309 `-changecur'
310 `-noverbose'
311
313 If a folder is given, it will become the current folder. The last mes‐
314 sage selected from a folder will become the current message, unless the
315 -nochangecur switch is enabled. If the -file switch or an absolute
316 pathname is used, the context will not be modified.
317
318
319
320nmh-1.7.1 2016-11-08 MHFIXMSG(1)