Next: , Previous: , Up: Library   [Contents][Index]

5.14 Mail Header Functions

Built-in Function: string message_header_encode (string text, [string enc, string charset])

Encode text in accordance with RFC 2047. Optional arguments:


Encoding to use. Valid values are ‘quoted-printable’, or ‘Q’ (the default) and ‘base64’, or ‘B’.


Character set. By default ‘UTF-8’.

If the function is unable to encode the string, it raises the exception e_failure.

For example:

set string "Keld Jørn Simonsen <>"
message_header_encode(string, "ISO-8859-1")
  ⇒ "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <>"
Built-in Function: string message_header_decode (string text, [string charset])

text must be a header value encoded in accordance with RFC 2047. The function returns the decoded string. If the decoding fails, it raises e_failure exception. The optional argument charset specifies the character set to use (default – ‘UTF-8’).

set string "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <>"
 ⇒ "Keld Jørn Simonsen <>"
Built-in Function: string unfold (string text)

If text is a “folded” multi-line RFC 2822 header value, unfold it. If text is a single-line string, return its unchanged copy.

For example, suppose that the message being processed contained the following header:

List-Id: Sent bugreports to

Then, applying unfold to its value24 will produce:

Sent bugreports to <>



For example:

prog header
  echo unfold($2)