[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Creating a MIME message is boring and non-trivial. Therefore,
a library called mml
has been defined that parses a language
called MML (MIME Meta Language) and generates
MIME messages.
The main interface function is mml-generate-mime
. It will
examine the contents of the current (narrowed-to) buffer and return a
string containing the MIME message.
2.1 Simple MML Example | An example MML document. | |
2.2 MML Definition | All valid MML elements. | |
2.3 Advanced MML Example | Another example MML document. | |
2.4 Encoding Customization | Variables that affect encoding. | |
2.5 Charset Translation | How charsets are mapped from MULE to MIME. | |
2.6 Conversion | Going from MIME to MML and vice versa. | |
2.7 Flowed text | Soft and hard newlines. |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here's a simple `multipart/alternative':
<#multipart type=alternative> This is a plain text part. <#part type=text/enriched> <center>This is a centered enriched part</center> <#/multipart> |
After running this through mml-generate-mime
, we get this:
Content-Type: multipart/alternative; boundary="=-=-=" --=-=-= This is a plain text part. --=-=-= Content-Type: text/enriched <center>This is a centered enriched part</center> --=-=-=-- |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The MML language is very simple. It looks a bit like an SGML application, but it's not.
The main concept of MML is the part. Each part can be of a different type or use a different charset. The way to delineate a part is with a `<#part ...>' tag. Multipart parts can be introduced with the `<#multipart ...>' tag. Parts are ended by the `<#/part>' or `<#/multipart>' tags. Parts started with the `<#part ...>' tags are also closed by the next open tag.
There's also the `<#external ...>' tag. These introduce `external/message-body' parts.
Each tag can contain zero or more parameters on the form `parameter=value'. The values may be enclosed in quotation marks, but that's not necessary unless the value contains white space. So `filename=/home/user/#hello$^yes' is perfectly valid.
The following parameters have meaning in MML; parameters that have no meaning are ignored. The MML parameter names are the same as the MIME parameter names; the things in the parentheses say which header it will be used in.
Content-Type
).
Content-Disposition
).
Content-Type
). See section 2.5 Charset Translation.
Content-Type
).
Content-Disposition
).
Content-Transfer-Encoding
). See section 2.5 Charset Translation.
Content-Description
).
Content-Disposition
).
Content-Disposition
).
Content-Disposition
).
Content-Disposition
).
smime
, pgp
or pgpmime
)
smime
,
pgp
or pgpmime
)
Parameters for `text/plain':
Parameters for `application/octet-stream':
Content-Type
).
Parameters for `message/external-body':
Content-Type
.)
Content-Type
.)
Content-Type
.)
Content-Type
).
Parameters for `sign=smime':
Parameters for `encrypt=smime':
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here's a complex multipart message. It's a `multipart/mixed' that contains many parts, one of which is a `multipart/alternative'.
<#multipart type=mixed> <#part type=image/jpeg filename=~/rms.jpg disposition=inline> <#multipart type=alternative> This is a plain text part. <#part type=text/enriched name=enriched.txt> <center>This is a centered enriched part</center> <#/multipart> This is a new plain text part. <#part disposition=attachment> This plain text part is an attachment. <#/multipart> |
And this is the resulting MIME message:
Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= --=-=-= Content-Type: image/jpeg; filename="~/rms.jpg" Content-Disposition: inline; filename="~/rms.jpg" Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAAwADABAREA/8QAHwAA AQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQR BRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF RkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEB AAA/AO/rifFHjldNuGsrDa0qcSSHkA+gHrXKw+LtWLrMb+RgTyhbr+HSug07xNqV9fQtZrNI AyiaE/NuBPOOOP0rvRNE880KOC8TbXXGCv1FPqjrF4LDR7u5L7SkTFT/ALWOP1xXgTuXfc7E sx6nua6rwp4IvvEM8chCxWxOdzn7wz6V9AaB4S07w9p5itow0rDLSY5Pt9K43xO66P4xs71m 2QXiGCbA4yOVJ9+1aYORkdK434lyNH4ahCnG66VT9Nj15JFbPdX0MS43M4VQf5/yr2vSpLnw 5ZW8dlCZ8KFXjOPX0/mK6rSPEGt3Angu44fNEReHYNvIH3TzXDeKNO8RX+kSX2ouZkicTIOc L+g7E810ulFjpVtv3bwgB3HJyK5L4quY/C9sVxk3ij/xx6850u7t1mtp/wDlpEw3An3Jr3Dw 34gsbWza4nBlhC5LDsaW6+IFgupQyCF3iHH7gA7c9R9ay7zx6t7aX9jHC4smhfBkGCvHGfrm tLQ7hbnRrV1GPkAP1x1/Hr+Ncr8Vzjwrbf8AX6v/AKA9eQRyYlQk8Yx9K6XTNbkgia2ciSIn 7p5Ga9Atte0LTLKO6it4i7dVRFJDcZ4PvXN+JvEMF9bILVGXJLSZ4zkjivRPDaeX4b08HOTC pOffmua+KkbS+GLVUGT9tT/0B68eeIpIFYjB70+OOVXyoOM9+M1eaWeCLzHPyHGO/NVWvJJm jQ8KGH1NfQWhXSXmh2c8eArRLwO3HSv/2Q== --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= This is a plain text part. --==-=-= Content-Type: text/enriched; name="enriched.txt" <center>This is a centered enriched part</center> --==-=-=-- --=-=-= This is a new plain text part. --=-=-= Content-Disposition: attachment This plain text part is an attachment. --=-=-=-- |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mm-body-charset-encoding-alist
((iso-2022-jp . 7bit) (iso-2022-jp-2 . 7bit) (utf-16 . base64) (utf-16be . base64) (utf-16le . base64)) |
As an example, if you do not want to have ISO-8859-1 characters
quoted-printable encoded, you may add (iso-8859-1 . 8bit)
to
this variable. You can override this setting on a per-message basis
by using the encoding
MML tag (see section 2.2 MML Definition).
mm-coding-system-priorities
nil
, which means to use the defaults in Emacs, but is
(iso-8859-1 iso-2022-jp iso-2022-jp-2 shift_jis utf-8)
when
running Emacs in the Japanese language environment. It is a list of
coding system symbols (aliases of coding systems are also allowed, use
M-x describe-coding-system to make sure you are specifying correct
coding system names). For example, if you have configured Emacs
to prefer UTF-8, but wish that outgoing messages should be sent in
ISO-8859-1 if possible, you can set this variable to
(iso-8859-1)
. You can override this setting on a per-message
basis by using the charset
MML tag (see section 2.2 MML Definition).
mm-content-transfer-encoding-defaults
qp-or-base64
may be used to indicate that for
each case the most efficient of quoted-printable and base64 should be
used.
qp-or-base64
has another effect. It will fold long lines so that
MIME parts may not be broken by MTA. So do quoted-printable
and
base64
.
Note that it affects body encoding only when a part is a raw forwarded
message (which will be made by gnus-summary-mail-forward
with the
arg 2 for example) or is neither the `text/*' type nor the
`message/*' type. Even though in those cases, you can override
this setting on a per-message basis by using the encoding
MML tag (see section 2.2 MML Definition).
mm-use-ultra-safe-encoding
nil
, it means that textual parts are encoded as
quoted-printable if they contain lines longer than 76 characters or
starting with "From " in the body. Non-7bit encodings (8bit, binary)
are generally disallowed. This reduce the probability that a non-8bit
clean MTA or MDA changes the message. This should never be set
directly, but bound by other functions when necessary (e.g., when
encoding messages that are to be digitally signed).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
During translation from MML to MIME, for each MIME part which has been composed inside Emacs, an appropriate charset has to be chosen.
If you are running a non-MULE Emacs, this process is simple: If the
part contains any non-ASCII (8-bit) characters, the MIME charset
given by mail-parse-charset
(a symbol) is used. (Never set this
variable directly, though. If you want to change the default charset,
please consult the documentation of the package which you use to process
MIME messages.
See section `Various Message Variables' in Message Manual, for example.)
If there are only ASCII characters, the MIME charset US-ASCII is
used, of course.
Things are slightly more complicated when running Emacs with MULE
support. In this case, a list of the MULE charsets used in the
part is obtained, and the MULE charsets are translated to
MIME charsets by consulting the table provided by Emacs itself
or the variable mm-mime-mule-charset-alist
for XEmacs.
If this results in a single MIME charset, this is used to encode
the part. But if the resulting list of MIME charsets contains more
than one element, two things can happen: If it is possible to encode the
part via UTF-8, this charset is used. (For this, Emacs must support
the utf-8
coding system, and the part must consist entirely of
characters which have Unicode counterparts.) If UTF-8 is not available
for some reason, the part is split into several ones, so that each one
can be encoded with a single MIME charset. The part can only be
split at line boundaries, though--if more than one MIME charset is
required to encode a single line, it is not possible to encode the part.
When running Emacs with MULE support, the preferences for which
coding system to use is inherited from Emacs itself. This means that
if Emacs is set up to prefer UTF-8, it will be used when encoding
messages. You can modify this by altering the
mm-coding-system-priorities
variable though (see section 2.4 Encoding Customization).
The charset to be used can be overridden by setting the charset
MML tag (see section 2.2 MML Definition) when composing the message.
The encoding of characters (quoted-printable, 8bit etc) is orthogonal
to the discussion here, and is controlled by the variables
mm-body-charset-encoding-alist
and
mm-content-transfer-encoding-defaults
(see section 2.4 Encoding Customization).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A (multipart) MIME message can be converted to MML
with the mime-to-mml
function. It works on the message in the
current buffer, and substitutes MML markup for MIME
boundaries. Non-textual parts do not have their contents in the buffer,
but instead have the contents in separate buffers that are referred to
from the MML tags.
An MML message can be converted back to MIME by the
mml-to-mime
function.
These functions are in certain senses "lossy"---you will not get back
an identical message if you run mime-to-mml
and then
mml-to-mime
. Not only will trivial things like the order of the
headers differ, but the contents of the headers may also be different.
For instance, the original message may use base64 encoding on text,
while mml-to-mime
may decide to use quoted-printable encoding, and
so on.
In essence, however, these two functions should be the inverse of each other. The resulting contents of the message should remain equivalent, if not identical.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Emacs MIME library will respect the use-hard-newlines
variable (see section `Hard and Soft Newlines' in Emacs Manual) when encoding a message, and the
"format=flowed" Content-Type parameter when decoding a message.
On encoding text, regardless of use-hard-newlines
, lines
terminated by soft newline characters are filled together and wrapped
after the column decided by fill-flowed-encode-column
.
Quotation marks (matching `^>* ?') are respected. The variable
controls how the text will look in a client that does not support
flowed text, the default is to wrap after 66 characters. If hard
newline characters are not present in the buffer, no flow encoding
occurs.
On decoding flowed text, lines with soft newline characters are filled
together and wrapped after the column decided by
fill-flowed-display-column
. The default is to wrap after
fill-column
.
mm-fill-flowed
nil
a format=flowed article will be displayed flowed.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by XEmacs shared group account on December, 19 2009
using texi2html 1.65.