]> diplodocus.org Git - nmh/blob - man/mhfixmsg.man
pending-release-notes: add mhshow's "-prefer", and mh-format's %(kibi/kilo)
[nmh] / man / mhfixmsg.man
1 .TH MHFIXMSG %manext1% "December 25, 2014" "%nmhversion%"
2 .\"
3 .\" %nmhwarning%
4 .\"
5 .SH NAME
6 mhfixmsg \- rewrite MIME messages with various transformations
7 .SH SYNOPSIS
8 .HP 5
9 .na
10 .B mhfixmsg
11 .RI [ +folder ]
12 .RI [ msgs " | "
13 .IR "absolute pathname" " | "
14 .RB \-file
15 .IR file ]
16 .RB [ \-decodetext
17 8bit/7bit |
18 .BR \-nodecodetext ]
19 .RB [ \-textcharset
20 .I charset
21 .RB "| " \-notextcharset ]
22 .RB [ \-reformat " | " \-noreformat ]
23 .RB [ \-replacetextplain " | " \-noreplacetextplain ]
24 .RB [ \-fixboundary " | " \-nofixboundary ]
25 .RB [ \-fixcte " | " \-nofixcte ]
26 .RB [ \-fixtype
27 .IR mimetype ]
28 .RB [ \-outfile
29 .IR outfile ]
30 .RB [ \-rmmproc
31 .IR program ]
32 .RB [ \-normmproc ]
33 .RB [ \-changecur " | " \-nochangecur ]
34 .RB [ \-verbose " | " \-noverbose ]
35 .RB [ \-version ]
36 .RB [ \-help ]
37 .ad
38 .SH DESCRIPTION
39 .B mhfixmsg
40 rewrites MIME messages, applying specific transformations such as
41 decoding of MIME-encoded message parts and repairing invalid MIME
42 headers.
43 .PP
44 MIME messages are specified in RFC 2045 to RFC 2049
45 (see
46 .IR mhbuild (1)).
47 The
48 .B mhlist
49 command is invaluable for viewing the content structure of MIME
50 messages.
51 .B mhfixmsg
52 passes non-MIME messages through without any transformations. If no
53 transformations apply to a MIME message, the original message or file
54 is not modified or removed.
55 .PP
56 The
57 .B \-decodetext
58 switch enables a transformation to decode each base64 and
59 quoted-printable text message part to the selected 8bit or 7bit
60 encoding. If 7bit is selected for a base64 part but it will only fit
61 8bit, as defined by RFC 2045, then it will be decoded to 8bit
62 quoted-printable. Otherwise, if the decoded text would not fit the
63 selected encoding, the part is not decoded (and a message will be
64 displayed if
65 .B \-verbose
66 is enabled).
67 .PP
68 When the
69 .B \-decodetext
70 switch is enabled, each carriage return character that precedes a
71 linefeed character is removed from text parts encoded in ASCII,
72 ISO-8859-x, UTF-8, or Windows-12xx.
73 .PP
74 The
75 .B \-textcharset
76 switch specifies that all text/plain parts of the message(s)
77 should be converted to
78 .IR charset .
79 Charset conversions require that
80 .B nmh
81 be built with
82 .IR iconv (3);
83 see the
84 .BR mhparam (1)
85 man page for how determine whether your
86 .B nmh
87 installation includes that.
88 To convert text parts other than text/plain, an external program can
89 be used, via the
90 .B \-reformat
91 switch.
92 .PP
93 The
94 .B \-reformat
95 switch enables a transformation for text parts in the message. For
96 each text part that is not text/plain and that does not have a
97 corresponding text/plain in a multipart/alternative part,
98 .B mhfixmsg
99 looks for a mhfixmsg-format-text/subtype profile entry that matches
100 the subtype of the part. If one is found and can be used to
101 successfully convert the part to text/plain,
102 .B mhfixmsg
103 inserts that text/plain part at the beginning of the containing
104 multipart/alternative part, if present. If not, it creates a
105 multipart/alternative part.
106 .PP
107 The
108 .B \-replacetextplain
109 switch broadens the applicability of
110 .B \-reformat
111 by always replacing a corresponding text/plain part, if one exists.
112 If
113 .B \-verbose
114 if enabled, the replacement will be shown as two steps: a removal of
115 the text/plain part followed by the usual insertion of a new part.
116 .PP
117 .B \-reformat
118 requires a profile entry for each text part subtype to be reformatted.
119 The mhfixmsg-format-text/subtype profile entries are based on external
120 conversion programs, and are used the same way that
121 .B mhshow
122 uses its mhshow-show-text/subtype entries. When
123 .B nmh
124 is installed, it searches for a conversion program for text/html
125 content, and if one is found, inserts a mhfixmsg-format-text/html
126 entry in %nmhetcdir%/mhn.defaults. An entry of the same name in the
127 user's profile takes precedence. The user can add entries for
128 other text subtypes to their profile.
129 .PP
130 The
131 .B \-fixboundary
132 switch enables a transformation to repair the boundary portion of the
133 Content-Type header field of the message to match the boundaries of
134 the outermost multipart part of the message, if it does not. That
135 condition is indicated by a \*(lqbogus multipart content in
136 message\*(rq error message from
137 .B mhlist
138 and other
139 .B nmh
140 programs that parse MIME messages.
141 .PP
142 The
143 .B \-fixcte
144 switch enables a transformation to change the
145 Content-Transfer-Encoding from an invalid value to 8bit in message
146 parts with a Content-Type of multipart, as required by RFC 2045,
147 Section 6.4. That condition is indicated by a \*(lqmust be encoded in
148 7bit, 8bit, or binary\*(rq error message from
149 .B mhlist
150 and other
151 .B nmh
152 programs that parse MIME messages.
153 .PP
154 The
155 .B \-fixtype
156 switch ensures that each part of the message has the correct MIME type
157 shown in its Content-Type header. It may be repeated. It is
158 typically used to replace \*(lqapplication/octet-stream\*(rq with a
159 more descriptive MIME type. It may not be used for multipart and
160 message types.
161 .PP
162 .B mhfixmsg
163 applies one transformation unconditionally: it removes an extraneous
164 trailing semicolon from the parameter lists of MIME header fields.
165 .PP
166 The
167 .B \-verbose
168 switch directs
169 .B mhfixmsg
170 to output informational message for each transformation applied.
171 .PP
172 The return status of
173 .B mhfixmsg
174 is 0 if all of the requested transformations are performed, or
175 non-zero otherwise.
176 .RB ( mhfixmsg
177 will not decode to binary content, but a request to do so is
178 not considered a failure, and is noted with
179 .BR \-verbose .)
180 If a problem is detected with any one of multiple messages such that
181 the return status is non-zero, then none of the messages will be
182 modified.
183 .PP
184 The
185 .B \-file
186 .I file
187 switch directs
188 .B mhfixmsg
189 to use the specified
190 file as the source message, rather than a message from a folder.
191 Only one file argument may be provided. The
192 .B \-file
193 switch is implied if
194 .I file
195 is an absolute pathname.
196 If the file is \*(lq-\*(rq, then
197 .B mhfixmsg
198 accepts the source message on the standard input stream. If
199 the
200 .B \-outfile
201 switch is not enabled when using the standard input stream,
202 .B mhfixmsg
203 will not produce a transformed output message.
204 .PP
205 .BR mhfixmsg ,
206 by default, transforms the message in place. If the
207 .B \-outfile
208 switch is enabled, then
209 .B mhfixmsg
210 does not modify the input message or file, but instead places its
211 output in the specified file. An outfile name of \*(lq-\*(rq
212 specifies the standard output stream.
213 .PP
214 Combined with the
215 .B \-verbose
216 switch, the
217 .B \-outfile
218 switch can be used to show what transformations
219 .B mhfixmsg
220 would apply without actually applying them, e.g.,
221 .PP
222 .RS 5
223 mhfixmsg -outfile /dev/null -verbose
224 .RE
225 .PP
226 As always, this usage obeys any
227 .B mhfixmsg
228 switches in the user's profile.
229 .PP
230 .B \-outfile
231 can be combined with
232 .B rcvstore
233 to add a single transformed message to a different folder, e.g.,
234 .PP
235 .RS 5
236 mhfixmsg -outfile - | \\
237 .RS 0
238 %nmhlibexecdir%/rcvstore +folder
239 .RE
240 .RE
241 .SS Summary of Applicability
242 The transformations apply to the parts of a message depending on
243 content type and/or encoding as follows:
244 .PP
245 .RS 5
246 .nf
247 .ta \w'\-fixboundary 'u
248 \-decodetext base64 and quoted-printable encoded text parts
249 \-textcharset text/plain parts
250 \-reformat text parts that are not text/plain
251 \-fixboundary outermost multipart part
252 \-fixcte multipart part
253 \-fixtype all except multipart and message parts
254 .fi
255 .RE
256 .PP
257 .SS "Backup of Original Message/File"
258 If it applies any transformations to a message or file,
259 and the
260 .B \-outfile
261 switch is not used,
262 .B mhfixmsg
263 backs up the original the same way as
264 .BR rmm .
265 That is, it uses the
266 .I rmmproc
267 profile component, if present. If not present,
268 .B mhfixmsg
269 moves the original message to a backup file.
270 The
271 .B \-rmmproc
272 switch may be used to override this profile component. The
273 .B \-normmproc
274 switch disables the use of any
275 .I rmmproc
276 profile component and negates all prior
277 .B \-rmmproc
278 switches.
279 .PP
280 .SS "Integration with inc"
281 .B mhfixmsg
282 can be used as an add-hook, as described in %docdir%/README-HOOKS.
283 Note that add-hooks are called from all
284 .B nmh
285 programs that add a message to a folder, not just
286 .BR inc .
287 Alternatively, a simple shell alias or function can be used to
288 call
289 .B mhfixmsg
290 immediately after a successful invocation of
291 .BR inc .
292 One approach could be based on:
293 .PP
294 .RS 5
295 msgs=`inc -format '%(msg)'` && [ -n "$msgs" ] && scan $msgs && \
296 mhfixmsg -nochangecur $msgs
297 .RE
298 .PP
299 Another approach would rely on adding a sequence to Unseen-Sequence,
300 which
301 .B inc
302 sets with the newly incorporated messages. Those could then be
303 supplied to
304 .BR mhfixmsg .
305 .SS "Integration with procmail"
306 By way of example, here is an excerpt from a procmailrc file
307 that filters messages through
308 .B mhfixmsg
309 before storing them in the user's
310 .I nmh-workers
311 folder. It also stores the incoming message in the
312 .I Backups
313 folder in a filename generated by
314 .BR mkstemp ,
315 which is a non-POSIX utility to generate a temporary file.
316 Alternatively,
317 .B mhfixmsg
318 could be called on the message after it is stored.
319 .PP
320 .RS 5
321 .nf
322 .ta \w'\-fixboundary 'u
323 PATH = %bindir%:$PATH
324 MAILDIR = `mhparam path`
325 #### The Backups directory is relative to MAILDIR.
326 MKSTEMP = 'mkstemp -directory Backups -prefix mhfixmsg'
327 MHFIXMSG = 'mhfixmsg -noverbose -file - -outfile -'
328 STORE = %nmhlibexecdir%/rcvstore
329
330 :0 w: nmh-workers/procmail.$LOCKEXT
331 * ^TOnmh-workers@nongnu.org
332 | tee `$MKSTEMP` | $MHFIXMSG | $STORE +nmh-workers
333 .fi
334 .RE
335 .PP
336 .SH FILES
337 .B mhfixmsg
338 looks for mhn.defaults in multiple locations: absolute pathnames are
339 accessed directly, tilde expansion is done on usernames, and files are
340 searched for in the user's
341 .I Mail
342 directory as specified in their profile. If not found there, the directory
343 .RI \*(lq %nmhetcdir% \*(rq
344 is checked.
345 .PP
346 .fc ^ ~
347 .nf
348 .ta \w'%nmhetcdir%/mhn.defaults 'u
349 ^$HOME/\&.mh\(ruprofile~^The user profile
350 ^%nmhetcdir%/mhn.defaults~^Default mhfixmsg conversion entries
351 .fi
352 .SH "PROFILE COMPONENTS"
353 .fc ^ ~
354 .nf
355 .ta 2.4i
356 .ta \w'ExtraBigProfileName 'u
357 ^Path:~^To determine the user's nmh directory
358 ^Current\-Folder:~^To find the default current folder
359 ^rmmproc:~^Program to delete original messages or files
360 .fi
361 .SH "SEE ALSO"
362 .IR inc (1),
363 .IR iconv (3),
364 .IR mh-profile (5),
365 .IR mhbuild (1),
366 .IR mhlist (1),
367 .IR mhparam (1),
368 .IR mhshow (1),
369 .IR mh-mkstemp (1),
370 .IR procmail (1),
371 .IR procmailrc (5),
372 .IR rcvstore (1),
373 .IR rmm (1)
374 .SH DEFAULTS
375 .nf
376 .RB ` +folder "' defaults to the current folder"
377 .RB ` msgs "' defaults to cur"
378 .RB ` "\-decodetext 8bit"'
379 .RB ` \-notextcharset '
380 .RB ` \-reformat '
381 .RB ` \-noreplacetextplain '
382 .RB ` \-fixboundary '
383 .RB ` \-fixcte '
384 .RB ` \-changecur '
385 .RB ` \-noverbose '
386 .fi
387 .SH CONTEXT
388 If a folder is given, it will become the current folder. The last
389 message selected from a folder will become the current message, unless
390 the
391 .B \-nochangecur
392 switch is enabled. If the
393 .B \-file
394 switch or an absolute pathname is used, the context will not be
395 modified.