Creating and Using MBF Files
MBF or Mailbox Format Files are text files designed to allow cross compatibility with other email transport systems that can accept ASCII text files into their mail streams. MBF files are essentially templates that contain a set of special formatting macros that enable MDaemon to transform an RFC-822 message into a variety of other text-based formats. Using MBFs, MDaemon can be configured to automatically reformat incoming mail into specific alternatives on a per mailbox basis. When a message arrives for an MDaemon account, the account's MBF file is used to reformat the incoming data before distributing it to the user.
MBFs are constructed as plain ASCII text files ending with the "*.MBF" file extension. They are scanned by the server for macros, which will be replaced by actual data from an incoming message. Lines beginning with the "#" character are ignored and are used for comments. Lines beginning with the ";" character are used to control the value of the reformatted message's file name. When the MBF processor sees a line that begins with the ";" character it assumes that the text following this character will describe either the prefix or the extension which the processor should use when creating new files.
The syntax is:
; msg-prefix = SMF<cr><lf>
; msg-ext = <cr><lf>
If an MBF file contained lines as shown above, all reformatted mail messages created using the MBF file would take the form "SMFxxxx" where "xxxx" represents a random but unique identifier. The maximum length of the prefix component is four characters. The maximum extension that can be specified is three characters. Note that the above example purposely excludes an extension. These directives are optional and are not required to be present in any MBF file. However, their inclusion provides a means of directly manipulating message file names, which may be useful in integrating MDaemon Server v8 with an existing MTA. The default msg-prefix value is "MD" and the default msg-ext is "MSG".
Attachment file names can be similarly manipulated using the following syntax:
; attach-prefix = ATTH<cr><lf>
; attach-ext = ZIP<cr><lf>
This example would generate unique names for file attachments of the form "ATTHxxxx.ZIP" where "xxxx" represents a random yet unique identifier. Like those for message file names, these directives are optional.
It is sometimes important to retain the original file's extension while generating a unique file name for it. To accomplish this use the "; attach-ext = ???" syntax. This causes MDaemon to retain the attachment's original extension. By default, auto-extracted attachments are decoded and stored in the user's FILES directory under their original file names.
MBF Macros and Examples
The following is a list of all macros available for use when constructing an MBF file. Following this list is a series of examples.
$HEADERS$ This macro will be replaced by all the original RFC-822 message headers - each separated by a
CRLF delimiter. Using this macro the MBF will obtain all the headers contained in the incoming message. Text immediately preceding this macro will be duplicated at the start of each expanded line.
For example: O-SMTP-HEADER: $HEADERS$ would place each of the original RFC-822 headers into the reformatted message each preceded by the text string "O-SMTP-HEADER:"
$HEADER:XX$ This macro will cause the value of the header specified in place of the "xx" to be expanded in the reformatted message. For example: If the original message has "TO: joe@mdaemon.com" then the $HEADER:TO$ macro will expand to "joe@mdaemon.com". If the original message has "Subject: This is the subject" then the $HEADER:SUBJECT$ macro would be replaced with the text "This is the subject"
$BODY$ This macro will be replaced by the entire message body. In an attempt to preserve character sets for different languages, MDaemon will read the message body as stream binary data rather than pure text, thus allowing a byte-for-byte copy of the message body.
$BODY-AS-TEXT$ This macro will be replaced by the entire message body as with the $BODY$ macro, except that MDaemon will read this as text rather than binary. This may not be compatible with all char sets. Text immediately preceding this template variable will be duplicated at the start of each expanded line; thus: >>$BODY-AS-TEXT$ would place each of the original RFC-822 message lines into the reformatted message with the addition of the string text ">>" preceding them. Text could also be added to the right of this macro.
$ATTACHMENTS$ This macro will be replaced by the entire list of all attached files extracted from the original message. Text immediately preceding this template variable will be duplicated at the start of each expanded line; thus: FILE-LIST $ATTACHMENTS$ would place each of the attachment file names into the reformatted message, each preceded by the text string "FILE-LIST". NOTE: This macro is only available when you are extracting attachments from the account.
$ATTACHMENTCOUNT$ This macro will be replaced with an integer value equal to the number of attachments extracted from the original message. NOTE: This macro is only available when you are extracting attachments from the account.
$ATTACHMENT(X)$ This macro will be replaced with the attachment file name of the relative attachment number passed in the X parameter. If the value in X is greater than the total number of attached files then the entire variable is removed and replaced with nothing.
$SENDER$ This macro resolves to the full address of the message originator and corresponds to the RFC-822 "From:" header.
$SENDERMAILBOX$ This macro resolves to the mailbox of the message originator. The mailbox is the portion of the email address to the left of the "@" symbol.
$SENDERDOMAIN$ This macro resolves to the domain of the message originator. This is the portion of the email address to the right of the "@" symbol.
$RECIPIENT$ This macro resolves to the full address of the message recipient.
$RECIPIENTMAILBOX$ This macro resolves to the mailbox of the message recipient. The mailbox is the portion of the email address to the left of the "@" symbol.
$RECIPIENTDOMAIN$ This macro resolves to the domain of the message recipient. The domain is the portion of the email address to the right of the "@" symbol.
$SUBJECT$ This macro resolves to the value of the RFC-822 "Subject" header.
$MESSAGEID$ This macro resolves to the value of the RFC-822 "Message-ID" header.
$CONTENTTYPE$ This macro resolves to the value of the RFC-822 "Content-Type" header.
$PARTBOUNDARY$ This macro resolves to the value of the MIME "Part-Boundary" value found in the RFC-822 "Content-Type" header for multipart messages.
$DATESTAMP$ This macro expands to an RFC-822 style date-time stamp line.
$ACTUALTO$ Some messages may contain an "ActualTo" field which generally represents the destination mailbox and host as it was entered by the original user prior to any reformatting or alias translation.
$ACTUALFROM$ Some messages may contain an "ActualFrom" field which generally represents the origination mailbox and host prior to any reformatting or alias translation.
$REPLYTO$ This macro resolves to the value found in the RFC-822 "ReplyTo" header.
$PRODUCTID$ This macro expands to the MDaemon Server v8 version information string.
\\XXX This variable specifies an ASCII character code (000 - 255) that should be inserted into the MBF file. This variable is always 5 characters long with the first two characters being "\\". This instructs the server to expect a three digit number which represents an ASCII character code. For example, \\012 will place the ASCII character 12 (a formfeed character) into the MBF file. The numeric value specified must be three characters long and padded with zeros if necessary.
Sample MBF file(s):
1) RFC-822.MBF
# RFC-822.mbf mailbox format for standard RFC-822 translations
# version 1.1
$HEADERS$
X-MBF-FILE: MDaemon Gateway to RFC-822 (RFC-822.MBF v3)
$BODY$
2) SMF70.MBF
# smf70.mbf mailbox format for SMF minimal submission format
# version 1.1
; msg-prefix = SMF
; msg-ext =
SMF70
TO: $RECIPIENTMAILBOX$ @ $RECIPIENTDOMAIN$
FROM: $SENDER$
SUBJECT: $SUBJECT$
DATE: $DATESTAMP$
ATTACHMENT: $ATTACHMENTS$
O-SMTP-HEADER: $HEADERS$
$BODY$
3) DIGEST.MBF
# digest.mbf default message format for digest mail
# version 1.0
Date: $HEADER:DATE$
From: $HEADER:FROM$
Subject: $HEADER:SUBJECT$
$BODY$
