mime(3tcl)

๐Ÿ“ฆ
version 2.0 ยท 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– 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 -canonical option is present, then the body is in canonical (raw) form, and you find it by consulting either the -file, -string, or -parts option. 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 -canonical option is not present, then the MIME part contained in either the -file or the -string option 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 โ€” the type/subtype describing 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, no parts, 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 key is provided, then a list of values of matching names is returned, without regard to case. case? never heard of her.
  • if -names is provided, a list of all keys is returned.

๐Ÿ’œ ::mime::setheader ๐Ÿ’œ

::mime::setheader token key value ?-mode write | append | delete?
  • if append is provided, creates a new header named key with the value of value added. yes, the original wording is a little chaotic, but we ride.
  • if write is provided, deletes any existing headers whose names match key and then creates a new header named key with the value of value.
  • if delete is 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. 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 (the value parameter 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@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 ๐ŸŽ

::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 ๐Ÿซถ

::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 ๐ŸŒˆ

  • 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 (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