Author: Felix Schwarz felix DOT schwarz AT web DOT de Last update: 18.02.2006 License: Feel free to use the information in this document as you like. ==================================== The TBB format ==================================== TheBat! (www.ritlabs.com) uses a proprietary file format with the suffix .tbb to store its mails on the hard disk. All available information about a mail is stored inside the tbb file. TheBat! creates additional files with the suffix tbi but they are only used as index files. If the get lost or become corrupt, TheBat will regenerate the index file without any information being lost. One exception to this is the "memo" functionality. Memos are stored in the TBI files. ==================================== What I know from using TheBat! ==================================== A mail is still present in the tbb file even if it was deleted. Only after "compressing" the folder it is really deleted. Obviously the "deleted" mail is only flagged and therefore not shown anymore. Attachments can be stored outside of the tbb file if configured. In this case a converter has to do more work. A mail can be marked with a user configurable flag. A mail can be unread and/or "parked". ==================================== TBB file format specification ==================================== Every TBB file consists of a global file header and the parts per message. ==================================== Global File Header The header has always the same length (3084 bytes). The file starts with a magic number "0x20 0x06 0x79 0x19" followed by two bytes which specify the size of the global header (including the magic number and the length bytes!). ==================================== The Message Part The message part has a per message header which is always 48 bytes long. This header is followed by a RFC 822 mail message. The Mail Header A mail header starts with another magic number: 0x21 0x09 0x70 0x19 0x30. bytes 0-3: 21 09 70 19 magic number bytes 4-7: 30 00 00 00 message header size bytes 8-11: 38 ed ad 7a bytes 12-15 WW WW WW WW received time (unix timestamp) (little endian! 15, 14, 13, 12) bytes 16-17: 07 00 id number (maybe display position) (little endian! 17, 16) bytes 18-19: 00 00 byte 20-23: XX 00 00 00 message status flag bytes 24-27: 00 00 00 00 bytes 28-31: YY YY YY YY message belongs to a certain color group bytes 32-35: VV VV VV VV priority status bytes 36-39: ZZ ZZ ZZ ZZ size of the variable part (little endian! 39, 38, 37, 36) bytes 40-43: 00 00 00 00 bytes 44-47: 00 00 00 00 The size of the RFC 822 message is specified by the bytes 36-39. The mail is followed by the next message or EOF. There is no way to know in advance if there is another message. ==================================== The message status flag: Bit 7654 3210 0000 0000 1 = yes, 0 = no Bit 0 deleted Bit 1 read Bit 2 answered Bit 3 parked Bit 4 has attachement Bit 5 attachment was deleted (?) Bit 6 flagged Bit 7 forwarded ==================================== The priority status field: 00 00 00 00 normal priority 05 00 00 00 high priority FB FF FF FF low priority ==================================== color groups: The four bytes are an identifier that is tied to the unique short name of a color group defined in MAIL/COLORS.INI. As it is always four bytes long I think it is a kind of a hash sum, maybe CRC 32. ==================================== Some observations: If an attachment is deleted manually, TheBat! deletes the old mail and creates a new one in the message database where the attachement is deleted. ==================================== Revisions: 18. Feb 2006 - incorporated suggestions from Chris Drake (global file header size, message header, message status flag)