[Dovecot] SQL insert?

Timo Sirainen tss at iki.fi
Mon Nov 29 23:29:36 EET 2010

On Mon, 2010-11-29 at 10:58 +0100, Oliver Berse wrote:

> I want to log some informations about a mail in a mysql database when the
> mail is saved to inbox (for a groupware). I use Dovecot 1.2.16 and the log
> message "msgid=<xxx>: saved mail to inbox" is generated in deliver.c. I
> find all the needed data in that file. But I'am not sure how to use the
> functions in sql-api.h or sql-api-private.h to send a simple SQL insert
> statement to the database. Can anyone give me a hint how to do this?

struct sql_db *db = sql_init("mysql", "host=localhost");

struct sql_transaction_context *trans = sql_transaction_begin(db);
sql_update(trans, "INSERT INTO blah");
sql_transaction_commit_s(trans, &error);

Plus add the necessary error handling. Also note that most Dovecot
binaries aren't linked with SQL libraries, so you need to do that too. 

Another possibility could be to do this via dict proxy. See
lib-dict/dict.h and e.g. how quota-dict uses it. You can then configure
a mapping to SQL database in a similar way.

More information about the dovecot mailing list