mime(n)
π NAME π
mime β manipulation of MIME body parts. That's the whole assignment, bestie. π¦
β¨ 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 π
So the mime library package is the one handing you all the commands you need to create and manipulate MIME body parts. Like, it's the whole toolkit. Periodt.
πΈ ::mime::initialize ?-canonical type/subtype ?-param {key value}...? ?-encoding value? ?-header {key value}...?? (-file name | -string value | -parts {token1 ... tokenN})
This one creates a MIME part and hands you back a token that represents it. Your little handle. Your VIP pass. ποΈ
- π¦ If the
-canonicaloption is present, then the body is in canonical (raw) form and is found by consulting either the-file,-string, or-partsoption.- On top of that, both the
-paramand-headeroptions may occur zero or more times to specify Content-Type parameters (e.g.,charset) and header keyword/values (e.g.,Content-Disposition), respectively. - Also,
-encoding, if present, specifies theContent-Transfer-Encodingwhen copying the body.
- On top of that, both the
- π 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 just does that. π
π ::mime::finalize token ?-subordinates all | dynamic | none?
Destroys the MIME part represented by token. Returns an empty string. Poof, gone, no notes. π
If the -subordinates option is present, it specifies which subordinates should also be destroyed. The default value is dynamic, destroying all subordinates which were created by ::mime::initialize together with the containing body part.
β¨ ::mime::getproperty token ?property | -names?
Returns a string or a list of strings containing the properties of a MIME part. So:
- call it with the name of a specific property β you get the corresponding value back;
- call it with
-namesβ you get a list of all properties; - call it with neither β you get a serialized array of properties and values. Surprise, bestie. π
The possible properties are:
- content β the
type/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.
- size β the approximate size of the content (unencoded)
π¦ ::mime::getheader token ?key | -names?
Returns the header of a MIME part as a dictionary with possibly-redundant keys. (Yes, possibly-redundant. It said what it said.)
- If key is provided, then a list of values of matching names, without regard to case, is returned.
- If
-namesis provided, a list of all keys is returned.
π ::mime::setheader token key value ?-mode write | append | delete?
Okay so this is the one that edits your headers, and the mode changes everything:
- If
appendis provided, creates a new header named key with the value of value is added. - If
writeis provided, deletes any existing headers whose names match key and then creates a new header named key with the value of value. - If
deleteis provided any existing header having a name that matches key is deleted.
Returns a list of strings containing the previous value associated with the key. Nostalgic. π₯²
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 (the value parameter is ignored).
π
::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 as 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.
If the -command option is absent, then the return value of ::mime::getbody is a string containing the MIME part's entire body.
π¨ Listen up, this part matters: if the option-decodeis absent, the return value computed above is returned as is. Which means it will be in the charset specified for the token and not the usualutf-8. If the option-decodeis present, however, the command will use the charset information associated with the token to convert the string from its encoding intoutf-8before returning it. π«Ά
π ::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. It returns an empty string. Lowkey iconic of it. β¨
π ::mime::buildmessage token
Returns the MIME part represented by token as a string. It is 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 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.
- address β
local@domain - comment β 822-style comment
- domain β the domain part (rhs)
- error β non-empty on a parse error
- group β this address begins a group
- friendly β user-friendly rendering
- local β the local part (lhs)
- memberP β this address belongs to a group
- phrase β the phrase part
- proper β 822-style address specification
- route β 822-style route specification (obsolete)
π ::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 .. 23 - lmonth β
January, February, ..., December - lweekday β
Sunday, Monday, ... Saturday - mday β
1 .. 31 - min β
0 .. 59 - mon β
1 .. 12 - month β
Jan, Feb, ..., Dec - proper β 822-style date-time specification
- rclock β elapsed seconds between then and now
- sec β
0 .. 59 - wday β
0 .. 6 (Sun .. Mon) - weekday β
Sun, Mon, ..., Sat - yday β
1 .. 366 - year β
1900 ... - zone β
-720 .. 720(minutes east of GMT)
π ::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. π€·ββοΈ
β ::mime::reversemapencoding charset_type
Maps MIME charset types onto tcl encoding names. Those that are unknown return "".
π 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.
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. (Respect, honestly. Not making everyone else do homework for no reason.)
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. 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.
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.
π SEE ALSO π
ftp, http, pop3, smtp
π₯ 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
okay that's the whole page, bestie!! π¦β¨ This was mime(n) from the tcllib source, version 1.7.2 β go forth and manipulate those body parts responsibly, ily, mwah π
π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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