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