mime(3tcl)
๐ NAME ๐
mime โ manipulation of MIME body parts, bestie. it's giving email internals, and honestly? iconic.
โจ SYNOPSIS โจ
package require Tcl 8.5 9
package require mime ?1.7.2?
::mime::initialize ?-canonical type/subtype ?-param {key value}...?
?-encoding value? ?-header {key value}...?? (-file name | -string value
| -parts {token1 ... tokenN})
::mime::finalize token ?-subordinates all | dynamic | none?
::mime::getproperty token ?property | -names?
::mime::getheader token ?key | -names?
::mime::setheader token key value ?-mode write | append | delete?
::mime::getbody token ?-decode? ?-command callback ?-blocksize octets??
::mime::copymessage token channel
::mime::buildmessage token
::mime::parseaddress string
::mime::parsedatetime (string | -now) property
::mime::mapencoding encoding_name
::mime::reversemapencoding charset_type
๐ฆ DESCRIPTION ๐ฆ
okay so the mime library package is literally the whole toolkit for creating and manipulating MIME body parts. that's the vibe. every command below is your bestie for handling one little slice of that world. ๐
๐ธ ::mime::initialize ๐ธ
::mime::initialize ?-canonical type/subtype ?-param {key value}...?
?-encoding value? ?-header {key value}...?? (-file name | -string value
| -parts {token1 ... tokenN})
creates a MIME part and hands you back a token that represents it. like a little name tag for your body part. adorable, functional.
- if the
-canonicaloption is present, then the body is in canonical (raw) form, and you find it by consulting either the-file,-string, or-partsoption. one of them, bestie.
and ALSO โ both the -param and -header options may occur zero or more times, to specify Content-Type parameters (e.g., charset) and header keyword/values (e.g., Content-Disposition), respectively. zero or more!! go off.
also also, -encoding, if present, specifies the Content-Transfer-Encoding when copying the body. noted. ๐ซถ
- if the
-canonicaloption is not present, then the MIME part contained in either the-fileor the-stringoption is parsed, dynamically generating subordinates as appropriate. it's giving "we'll figure out the family tree as we go".
๐ท ::mime::finalize ๐ท
::mime::finalize token ?-subordinates all | dynamic | none?
destroys the MIME part represented by token. rip. it returns an empty string.
if the -subordinates option is present, it specifies which subordinates should also be destroyed. the default value is dynamic, which destroys all subordinates which were created by ::mime::initialize together with the containing body part. they all go down together. tragic, but efficient. ๐
๐ ::mime::getproperty ๐
::mime::getproperty token ?property | -names?
returns a string or a list of strings containing the properties of a MIME part.
- if you invoke it with the name of a specific property โ you get that value back.
- if you hit it with
-namesโ you get a list of ALL the properties. - otherwise โ you get a serialized array of properties and values. surprise! ๐
the possible properties are:
contentโ thetype/subtypedescribing the content.encodingโ the"Content-Transfer-Encoding".paramsโ a list of"Content-Type"parameters.partsโ a list of tokens for the part's subordinates. this property is present only if the MIME part has subordinates. no subordinates, noparts, periodt.sizeโ the approximate size of the content (unencoded).
๐ ::mime::getheader ๐
::mime::getheader token ?key | -names?
returns the header of a MIME part as a dictionary with possibly-redundant keys. yes, redundant keys. it's fine. it's a whole thing.
- if
keyis provided, then a list of values of matching names is returned, without regard to case. case? never heard of her. - if
-namesis provided, a list of all keys is returned.
๐ ::mime::setheader ๐
::mime::setheader token key value ?-mode write | append | delete?
- if
appendis provided, creates a new header namedkeywith the value ofvalueadded. yes, the original wording is a little chaotic, but we ride. - if
writeis provided, deletes any existing headers whose names matchkeyand then creates a new header namedkeywith the value ofvalue. - if
deleteis provided, any existing header having a name that matcheskeyis deleted.
returns a list of strings containing the previous value associated with the key. nostalgia. ๐ฅฒ
the value for -mode is one of:
writeโ the key/value is either created or overwritten (the default).appendโ a new value is appended for the key (creating it as necessary).deleteโ all values associated with the key are removed (thevalueparameter is ignored). bye bestie ๐
๐ง ::mime::getbody ๐ง
::mime::getbody token ?-decode? ?-command callback ?-blocksize octets??
returns a string containing the body of the leaf MIME part represented by token in canonical form.
if the -command option is present, then it is repeatedly invoked with a fragment of the body, like this:
uplevel #0 $callback [list "data" $fragment]
(the -blocksize option, if present, specifies the maximum size of each fragment passed to the callback.)
when the end of the body is reached, the callback is invoked as:
uplevel #0 $callback "end"
alternatively, if an error occurs, the callback is invoked as:
uplevel #0 $callback [list "error" reason]
regardless, the return value of the final invocation of the callback is propagated upwards by ::mime::getbody. the last word wins. main character energy. ๐
if the -command option is absent, then the return value of ::mime::getbody is a string containing the MIME part's entire body.
if the option -decode is absent, the return value computed above is returned as is. this means it will be in the charset specified for the token and not the usual utf-8. if the option -decode is present, however, the command will use the charset information associated with the token to convert the string from its encoding into utf-8 before returning it. glow-up included. โจ
โญ ::mime::copymessage โญ
::mime::copymessage token channel
copies the MIME represented by token part to the specified channel. the command operates synchronously, and uses fileevent to allow asynchronous operations to proceed independently. multitasking queen. it returns an empty string.
๐ ::mime::buildmessage ๐
::mime::buildmessage token
returns the MIME part represented by token as a string. it's similar to ::mime::copymessage, only it returns the data as a return string instead of writing to a channel. same energy, different delivery method. ๐
๐ ::mime::parseaddress ๐
::mime::parseaddress string
takes a string containing one or more 822-style address specifications and returns a list of serialized arrays, one element for each address specified in the argument. if the string contains more than one address, they will be separated by commas.
each serialized array contains the properties below. note that one or more of these properties may be empty. not every field is gonna show up to the party.
addressโlocal@domaincommentโ 822-style commentdomainโ the domain part (rhs)errorโ non-empty on a parse errorgroupโ this address begins a groupfriendlyโ user-friendly renderinglocalโ the local part (lhs)memberPโ this address belongs to a groupphraseโ the phrase partproperโ 822-style address specificationrouteโ 822-style route specification (obsolete)
๐ ::mime::parsedatetime ๐
::mime::parsedatetime (string | -now) property
takes a string containing an 822-style date-time specification and returns the specified property as a serialized array.
the list of properties and their ranges are:
hourโ0 .. 23lmonthโJanuary, February, ..., DecemberlweekdayโSunday, Monday, ... Saturdaymdayโ1 .. 31minโ0 .. 59monโ1 .. 12monthโJan, Feb, ..., Decproperโ 822-style date-time specificationrclockโ elapsed seconds between then and nowsecโ0 .. 59wdayโ0 .. 6 (Sun .. Mon)weekdayโSun, Mon, ..., Satydayโ1 .. 366yearโ1900 ...zoneโ-720 .. 720(minutes east of GMT)
๐ซถ ::mime::mapencoding ๐ซถ
::mime::mapencoding encoding_name
maps tcl encodings onto the proper names for their MIME charset type. this is only done for encodings whose charset types were known. the remaining encodings return "" for now. they're still figuring themselves out. we support them. ๐ฑ
๐ซ ::mime::reversemapencoding ๐ซ
::mime::reversemapencoding charset_type
maps MIME charset types onto tcl encoding names. those that are unknown return "". mystery encodings stay mysterious. ๐ฎ
๐ญ KNOWN BUGS ๐ญ
- Tcllib Bug #447037
this problem affects only people which are using Tcl and Mime on a 64-bit system. the currently recommended fix for this problem is to upgrade to Tcl version 8.4. this version has extended 64 bit support and the bug does not appear anymore. slay, honestly.
the problem could have been generally solved by requiring the use of Tcl 8.4 for this package. we decided against this solution, as it would force a large number of unaffected users to upgrade their Tcl interpreter for no reason. considerate king behavior.
see Ticket 447037 [/tktview?name=447037] for additional information.
๐ BUGS, IDEAS, FEEDBACK ๐
this document, and the package it describes, will undoubtedly contain bugs and other problems. bestie, no shade, it's just how docs work. please report such in the category mime of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either package and/or documentation. we wanna hear it. ๐ฃ๏ธ
when proposing code changes, please provide unified diffs, i.e. the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk. ๐
๐ SEE ALSO ๐
ftphttppop3smtp
๐ฅ KEYWORDS ๐ฅ
email, internet, mail, mime, net, rfc 2045, rfc 2046, rfc 2049, rfc 821, rfc 822, smtp
๐ CATEGORY ๐
Text processing
๐ COPYRIGHT ๐
Copyright (c) 1999-2000 Marshall T. Rose
and that's the whole page, bestie ๐ฆ โ brought to you by tcllib 1.7.2, dated the mime(3tcl) era, and yes, the manual name is literally mime, we've been over this ๐ mwah, go parse something pretty โจ
๐ฆ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 ยท Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 ยท Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 ยท Tcl
- Copyright (c) 1999-2000 Marshall T\&. Rose
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms