Synchronet Message Base (SMB) Specification Version 1.00
--------------------------------------------------------

SDT (Data)
---
256 byte records for self-packing


SRA (Record allocation)
---
2 bytes per record in data file to indicate allocated or not. Each record can
be used by up to 65,535 index entries.
Recreatable if .SDT and .SVI exist.


CRC (CRCs for dupe checking)
---
32-bit CRCs of last x number of messages posted/imported
Recreatable if .SDT and .SVI exist.


SFI (Fixed length/Fast index)
---

Index Record:

typedef struct {

    ushort  to;             // 16-bit CRC of recipient name (lower case)
    ushort  from;           // 16-bit CRC of sender name (lower case)
    ushort  title;          // 16-bit CRC of title/subject (lower case)
    ushort  attr;           // attributes (read, permanent, etc.)
    ulong   offset;         // offset into variable length index file

    } idxrec_t;
Recreatable if .SDT and .SVI exist.


SVI (Variable length index)
---

Header Fixed Portion:

typedef struct {

    uchar   id[4];          // text or binary unique hdr ID
    ushort  version;        // version number (initially 100h for 1.00)
    ushort  length;         // length including this struct

    } varidxhdr_t;

Header #1 Variable Porition:

typedef struct {

    ulong   base_msg;       // first message number
    ulong   total_msgs;     // total messages
    ulong   index_offset;   // byte offset to first index entry

    } smbhdr_t;


Header #1 Contents:

varidxhdr.id="SMB\x1a";     // <S> <M> <B> <^Z>
varidxhdr.version=0x100;
varidxhdr.length=sizeof(varidxhdr_t)+sizeof(smbhdr_t); // 20
smbhdr_t header;


Additional headers from TPDs must have initial 8 bytes in varidxhdr_t
format, length must include size of structure defined above (8), and
index_offset of smbhdr_t must be changed to include the size of the 
additional header(s).

Index Records (normally starting at offset 20):

Index Record Fixed portion:

typedef struct {

    ushort  type;           // Message type (normally 0)
    ushort  version;        // Version of type (initially 100h for 1.00)
    ushort  length;         // Total length of fixed record + all fields
    ushort  fattr;          // Fixed index attributes (bit field) (duped)
    ulong   attr;           // Message attributes (bit field)
    ulong   mode;           // Message mode
    ulong   xlat;           // Translation (See MSGXLAT_* for values)
    ulong   netattr;        // Network attributes
    ushort  dest_type;      // Destination type (See TYP_* for values)
    ushort  orig_type;      // Origin type
    ushort  from_type;      // From type
    ushort  dest_net;       // Destination network type (See NET_* for values)
    ushort  orig_net;       // Network type originally exported into
    ushort  from_net;       // Network type imported from
    ushort  prio;           // Message priority (0 == lowest priority)
    ulong   time_written;   // Time message was written (unix format)
    ulong   time_read;      // Time message was read
    ulong   time_imported;  // Time message was imported
    ulong   time_exported;  // Time message was last exported
    ulong   number;         // Message number
    ulong   thread_orig;    // Original message number in thread
    ulong   thread_next;    // Next message in thread
    ulong   thread_first;   // First reply to this message
    ulong   offset;         // Offset for buffer into data file (0 or mod 256)
    ushort  data_fields;    // Total number of data fields
    dfield_t dfield[data_fields];
    ifield_t ifield[];

    } varidxrec_t;


typedef struct {

    ulong   type;           // Type of data field
    ulong   offset;         // Offset into buffer 
    ulong   length;         // Length of data field

    } dfield_t;


typedef struct {

    ulong   type;
    ulong   length;         // Length of buffer
    ulong   buf[length];

    } ifield_t;


typedef struct {

    ulong   type;           // Specifier for type of 'str'
    uchar   *str;           // ASCIIZ filename or other string data

    } typestr;

typedef struct {

    ulong   type;           // Specifier for type of 'dat'
    uchar   *dat;           // Binary data

    } typedat;


Valid ifields types:

Val Name                Data    Description
--- ----                ----    -----------
00h RECEIVERNAME        ASCIIZ  Recipent's name (person or process).
                                If not included, assumed "All".

01h AUTHORNAME          ASCIIZ  Original author of message (if forwarded).
                                If not included, assumed same as SENDERNAME.

02h SENDERNAME          ASCIIZ  Sender's name (person or process).
                                If not included, assumed "Anonymous".

03h SUBJECT             ASCIIZ  Subject/title of message.

04h RECEIVERGROUP       ASCIIZ  Recipent's group name.
                                Multiple group fields may be specified.

05h SENDERGROUP         ASCIIZ  Sender's group name.
                                Multiple group fields may be specified.

10h FILEATTACH          ASCIIZ  Name of attached file(s).
                                Wildcards allowed.
                                MSG_FILEATTACH attribute must be set.

11h DESTFILE            ASCIIZ  Destination name for attached file(s).
                                Wildcards allowed.
                                FILEATTACH index field must be included.

12h FILEATTACHLIST      ASCIIZ  Name of ASCII list of attached filenames.
                                Wildcards not allowed in ASCII list filename.
                                Wildcards allowed in ASCII list.
                                MSG_FILEATTACH attribute must be set.

13h DESTFILELIST        ASCIIZ  Name of ASCII list of destination filenames.
                                Wildcards not allowed in ASCII list filename.
                                Wildcards allowed in ASCII list.

14h FILEREQUEST         ASCIIZ  Name of requested file.
                                Wildcards allowed.
                                MSG_FILEREQUEST attribute must be set.

15h FILEPASSWORD        ASCIIZ  Password for FILEREQUEST.

16h FILEREQUESTLIST     ASCIIZ  Name of ASCII list of filenames to request.
                                Wildcards allowed.

17h FILEPASSWORDLIST    ASCIIZ  Name of ASCII list of passwords for
                                FILEREQUESTLIST.

20h DISPLAYATTACH       typestr Type and filename of attached display file.
                                MSG_FILEATTACH attribute must be set.
                                See Display Types for valid typestr.type
                                values.

21h RASTERATTACH        typestr Type and filename of attached raster image file
                                for display.
                                MSG_FILEATTACH attribute must be set.
                                See Raster Types for valid typestr.type values.

22h VECTORATTACH        typestr Type and filename of attached vector image file
                                for display.
                                MSG_FILEATTACH attribute must be set.
                                See Vector Types for valid typestr.type values.

23h ANIMATTACH          typestr Type and filename of attached graphical
                                animation file for display.
                                MSG_FILEATTACH attribute must be set.
                                See Animation Types for valid typestr.type
                                values.

24h FONTATTACH          typestr Type and filename of attached font definition
                                file.
                                MSG_FILEATTACH attribute must be set.
                                See Font Types for valid typestr.type values.

25h SOUNDATTACH         typestr Type and filename of attached sound file for
                                playback.
                                MSG_FILEATTACH attribute must be set.
                                See Sound Types for valid typestr.type values.

26h PRESENTATTACH       typestr Type and filename of attached presentation
                                definition file.
                                MSG_FILEATTACH attribute must be set.
                                See Present Types for valid typestr.type
                                values.

27h MMEDIAATTACH        typestr Type and filename of attached multimedia file
                                for playback.
                                MSG_FILEATTACH attribute must be set.
                                See Multimedia Types for valid typestr.type
                                values.

28h APPDATAATTACH       typestr Name of attached application data file for
                                process/display.
                                MSG_FILEATTACH attribute must be set.
                                See Application Data Types for valid
                                typestr.type values.

30h DISPLAYTRIGGER      typestr Type and filename of triggered display file.
                                See Display Types for valid typestr.type
                                values.

31h RASTERTRIGGER       typestr Type and filename of attached raster image file
                                for display.
                                See Raster Types for valid typestr.type values.

32h VECTORTRIGGER       typestr Type and filename of attached vector image file
                                for display.
                                See Vector Types for valid typestr.type values.

33h ANIMTRIGGER         typestr Type and filename of attached graphical
                                animation file for display.
                                See Animation Types for valid typestr.type
                                values.

34h FONTTRIGGER         typestr Type and filename of attached font definition
                                file.
                                See Font Types for valid typestr.type values.

35h SOUNDTRIGGER        typestr Type and filename of attached sound file for
                                playback.
                                See Sound Types for valid typestr.type values.

36h PRESENTTRIGGER      typestr Type and filename of attached presentation
                                definition file.
                                See Present Types for valid typestr.type
                                values.

37h MMEDIATRIGGER       typestr Type and filename of attached multimedia file
                                for playback.
                                See Multimedia Types for valid typestr.type
                                values.

38h APPDATATRIGGER      typestr Name of attached application data file for
                                process/display.
                                See Application Data Types for valid
                                typestr.type values.

40h IFIELD_ALLOCATED    undef   Allocated for later update/addition to index

80h DESTADDRESS         addr_t  Network address of destination system.

81h ORIGADDRESS         addr_t  Network address of originating system.

82h FROMADDRESS         addr_t  Network address of last system to passthrough

90h FIDOKLUDGE          ASCIIZ  FTS-compliant "kludge" line not otherwise
                                represented here. All data not relevant to
                                the actual kludge line, inlcuding leading
                                and trailing white space and ^A (01h) chars
                                should be removed.
                                Maximum length is 255 characters.
                                INTL, TOPT, and FMPT must never be stored
                                as separate ifields. Their data must be
                                extracted and use for the address ifields.

91h FIDOMSGID           ASCIIZ  Message identification string.
                                Maximum length is 100 characters.

92h FIDOREPLYID         ASCIIZ  Message reply data.
                                Maximum length is 100 characters.

93h FIDOPID             ASCIIZ  Program indentification string.
                                Maximum length is 100 characters.

94h FIDOTRACE           ASCIIZ  This is also referred to as ^aVia
                                information in FTNs. It contains information
                                about a system which the message has
                                travelled through.

                                The format of the field is

                                <YYYYMMDDHHMMSS><Network address> where:

                                YYYY is the year (1992-9999)
                                MM is the month (01-12)
                                DD is the day (01-31)
                                HH is the hour (00-23)
                                MM is the minute (00-59)
                                SS is the second (00-59)

                                The timestamp is stored in ASCII (0-9)
                                characters. The network address is the
                                address of the system. It is expressed in
                                ASCII notation in the native format of the
                                forwarding system.

95h FIDOSEENBY2D        ASCIIZ  Used to store two-dimensional (net/node)
                                SEEN-BY information often used in FTN
                                conference environments. Only the actual
                                SEEN-BY data is stored and ^aSEEN-BY: or
                                SEEN-BY: is stripped along with any leading
                                and trailing white space characters.

96h FIDOPATH2D          ASCIIZ  Used to store two-dimensional (net/node)
                                PATH information often used in FTN
                                conference environments. Only the actual
                                PATH data is stored and ^aPATH: is stripped
                                along with any leading and trailing white
                                space characters.

97h FIDOFLAGS           ASCIIZ  Used to store the FTN FLAGS kludge
                                information. Note that all FLAG options that
                                have binary representation in the SMB index
                                must be removed from the FLAGS string prior
                                to storing it. Only the actual flags option
                                string is stored and ^aFLAGS is stripped
                                along with any leading and trailing white
                                space characters.

98h TZUTCINFO           ASCIIZ  Time zone information. This subfield
                                consists of four mandatory bytes and one
                                optional. The first character may be a plus
                                (+) or a minus (-) character to indicate a
                                location east (plus) or west (minus) of UTC
                                0000. The plus character is implied unless
                                the first character is a minus character.
                                The following four bytes must be digits in
                                the range zero through nine and indicates
                                the offset in hours and minutes. E.g. 0100
                                indicates an offset of one hour east of UTC.

typedef struct {

    ushort  type;
    uchar   addr[];

    } addr_t;


typedef struct {

    ushort  zone;
    ushort  net;
    ushort  node;
    ushort  point;

    } fidoaddr_t;


typedef ulong postlinkaddr_t;


Valid values for addr_t.type:

ADDR_UNKNOWN        0       // data of address is of type ASCIIZ (unknown net)
ADDR_FIDO           1       // data of address is of type fidoaddr_t
ADDR_POSTLINK       2       // data of address is of type postlinkaddr_t
ADDR_QWK            3       // data of address is of type ASCIIZ
ADDR_UUCP           4       // data of address is of type ASCIIZ


Definition for bits in idxrec_t.attr and varidxrec_t.fattr:

MSG_PRIVATE                 // Private
MSG_READ                    // Read by addressee
MSG_PERMANENT               // Permanent
MSG_LOCKED                  // Msg is locked, no editing possible
MSG_DELETED                 // Msg is deleted


Definition for bits in varidxrec_t.attr:

MSG_FILEREQUEST             // File request
MSG_FILEATTACH              // File(s) attached to Msg
MSG_TRUNCFILE               // Truncate file(s) when sent
MSG_KILLFILE                // Delete file(s) when sent
MSG_RECEIPTREQ              // Return receipt requested
MSG_CONFIRMREQ              // Confirmation receipt requested
MSG_NODISP                  // Msg may not be displayed to user


Definition for bits in varidxrec_t.netattr:

MSG_LOCAL                   // Msg created locally
MSG_INTRANSIT               // Msg is in-transit
MSG_SENT                    // Sent to remote
MSG_KILLSENT                // Kill when sent
MSG_ARCHIVESENT             // Archive when sent
MSG_HOLD                    // Hold for pick-up
MSG_CRASH                   // Crash
MSG_IMMEDIATE               // Send Msg now, ignore restrictions
MSG_DIRECT                  // Send directly to destination
MSG_GATE                    // Send via gateway
MSG_ORPHAN                  // Unknown destination
MSG_FPU                     // Force pickup
MSG_TYPELOCAL               // Msg is for local use only
MSG_TYPEECHO                // Msg is for conference distribution
MSG_TYPENET                 // Msg is direct network mail


Definition for bits in varidxrec_t.xlat:

MSGXLAT_ENCRYPT             // Msg text is encrypted
MSGXLAT_ESCAPED             // Msg text is seven bit ASCII
MSGXLAT_COMPRESS1           // Msg text is compressed type 1
MSGXLAT_COMPRESS2           // Msg text is compressed type 2
MSGXLAT_COMPRESS3           // Msg text is compressed type 3
MSGXLAT_COMPRESS4           // Msg text is compressed type 4


Valid values for varidxrec_t.dest_type and varidxrec_t.orig_type:

TYP_PERSON          0       // To or from person
TYP_PROCESS         1       // To or from process


Network types:

NET_NONE            0       // Locally created
NET_UNKNOWN         1       // Unknown network type
NET_FIDO            2       // FTN network
NET_POSTLINK        3       // PostLink network
NET_QWK             4       // QWK based network
NET_UUCP            5       // UUCP based network


Display types:

DISPLAY_ASCII       0       // Pure ASCII printable characters
DISPLAY_ANSI        1       // ANSI escape sequences
DISPLAY_AVATAR      2       // AVATAR escape sequences
DISPLAY_LVI         3       // LVI escape sequences


Raster types:

RASTER_UNKNOWN      0       // Use file signature header to determine format
RASTER_GIF          1       // Compuserve Graphics Interchange Format
RASTER_TIF          2       // Tagged Image Format (Aka TIFF)
RASTER_TGA16        3       // TrueVision Graphics 16-bit
RASTER_TGA24        4       // TrueVision Graphics 24-bit
RASTER_TGA32        5       // TrueVision Graphics 32-bit
RASTER_PCX                  // ZSoft PaintBrush graphics
RASTER_BMP                  // Windows Bitmap
RASTER_PCD


Vector types:

VECTOR_UNKNOWN      0       // Use file signature header to determine format
VECTOR_RIP          1       // Remote Imaging Protocol Script (RIPscrip)
VECTOR_CDR          2       // Corel Draw!
VECTOR_CGM          3       // Computer Graphics Metafile
VECTOR_WMF          4       // Windows Metafile


Animation types:

ANIM_UNKNOWN        0       // Use file signature header to determine format
ANIM_FLI            1       // Autodesk animator
ANIM_FLC            2       // Autodesk


Multimedia types:

MMEDIA_UNKNOWN      0       // Use file signature header to determine format
MMEDIA_QTIME        1       // Quick-time
MMEDIA_AVI          2       // Windows Auto/Video Interleave


Font types:

FONT_UNKNOWN        0       // Use file signature header to determine format
FONT_TTF            1       // Windows True Type
FONT_PFB            2       // PostScript Type 2 Font
FONT_PFM            3       // ""


Sound types:

SOUND_UNKNOWN       0       // Use file signature header to determine format
SOUND_MOD           1       // Sound Blaster MOD format
SOUND_WAV           2       // Wave table format
SOUND_MID           3       // Midi format


Application Data types:

APPDATA_UNKNOWN     0       // Use file signature header to determine format
APPDATA_WORDPERFECT 1       // Wordperfect Document
APPDATA_LOTUS123WKS 2       // Lotus 123 Worksheet


Valid values for dfield_t.type:

Val Name                Data    Description
--- ----                ----    -----------
00h DATA_BODY           undef   Displayable text (body of message).
                                Included in duplicate message checking.

01h DATA_SOUL           undef   Non-displayed text.
                                Not normally displayed. Not necessarily
                                displayable.
                                Included in duplicate message checking.

02h DATA_TAIL           undef   Displayable text (tag/tear/origin lines, etc).
                                Not included in duplicate message checking.

03h DATA_WING           undef   Non-displayed text.
                                Not normally displayed. Not necessarily
                                displayable.
                                Not included in duplicate message checking.

20h DISPLAYEMBED        typedat Type and data of embedded display file.
                                See Display Types for valid typedat.type
                                values.

21h RASTEREMBED         typedat Type and data of embedded raster image file
                                for display.
                                See Raster Types for valid typedat.type values.

22h VECTORATTACH        typedat Type and data of embedded vector image file
                                for display.
                                See Vector Types for valid typedat.type values.

23h ANIMATTACH          typedat Type and data of embedded graphical animation
                                file for display.
                                See Animation Types for valid typedat.type
                                values.

24h FONTATTACH          typedat Type and data of embedded font definition file.
                                See Font Types for valid typedat.type values.

25h SOUNDATTACH         typedat Type and data of embedded sound file for
                                playback.
                                See Sound Types for valid typedat.type values.

26h PRESENTATTACH       typedat Type and data of embedded presentation
                                definition file.
                                See Present Types for valid typedat.type
                                values.

27h MMEDIAATTACH        typedat Type and data of embedded multimedia file
                                for playback.
                                See Multimedia Types for valid typedat.type
                                values.

28h APPDATAATTACH       typedat Type and data of embedded application data file
                                for process/display.
                                See Application Data Types for valid
                                typedat.type values.

40h DFIELD_ALLOCATED    undef   Space allocated for future update/expansion
