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