Document toolboxDocument toolbox

Custmail

The class Custmail handles storing incoming mails, typically from an IMAP server.

The mail accounts are defined by the class CustmailAccount and the IMAP API is provided by the class Imap.

The mail accounts are read regularly, typically every hour, although there is a patch which causes mails to be read more often.

The mail data (attachments, images etc) is stored on disk; only the mail body is stored in the DB.

When a mail has been read from the mail server, MB determines which companies and persons are referenced by the mail addresses (see below), and then creates a Custmail object for each. Then MB tries to associate the mail with a task (see below).

Customer association

MB looks at the email addresses in a mail (from, to, CC) and tries to determine which companies the mail should be associated with.

For each email address it finds any company whose email address matches exactly. If the “Search domain” settings is set in the CRM module, then it will also include companies whose WWW address matches partially, eg. a mail to 'bobo@ventu.dk' will be associated with a company whose WWW address includes 'ventu.dk'.

MB also looks for persons whose primary email matches exactly; if the person was associated with a company at the date of the mail, then the mail will also be associated with that company.

Task association

If a mail has a subject which ends in [Opgave#XXX], where 'Opgave' is the translation of the word 'Task' and 'XXX' is a task ID, then the mail will be associated with the task.

Message ID

Microbizz uses a 32 char string as message ID for each mail. The string is an MD5 sum of the various info, including the IMAP folder, mail account and mail UID reported by IMAP.

Keep track of known mails

The table custmail_isparsed holds the message IDs of all mails that have been read for an account.

Ignoring mails

The table custmail_ignore holds the message IDs of all mails that should be ignored, ie. should not be read from the mail server.

This is used when deleting a mail from MB - without a list of mails to ignore, the mail would just be reread a little later.

Storage

The attachments and other files are stored with the other files for the contract. To prevent storing many copies of the same file (eg. a logo included in all outgoing mails) the files are stored under the MD5 sum of their contents.

The folder custmail_attachments/ holds a subfolder for each 3-letter combination that has appear at the start of an MD5 sum; the subfolder then holds all the files with MD5 sums that start with those 3 letters. Eg. if the MD5 sum of a file is 8e2eedd71cf33da246e18812999a6df4 then it will be stored in the file custmail_attachments/8e2/8e2eedd71cf33da246e18812999a6df4.