Skip to content

Commit

Permalink
* sort.h, sort.c, sortmodule.c, modules/sortsieve.c:
Browse files Browse the repository at this point in the history
major work on the Sieve interface.
* sievecmd.c:
bugfixes.
* configure.in, acinclude.m4:
Added a rudimentary summary at the end.
* db.h, db.c:
added arguments to db_replycache functions, changed them to work by
days since the last reply rather than seconds, bugfixes in the
db_rename_sievescript function.
* modules/dbmysql.c, modules/dbpgsql.c, pipe.c:
change the replycache sql chunk to days rather than seconds.
* dbmail-message.h, dbmail-message.c:
added envelope sender's address (more to do on this though).
* sql/postgresql/add_replycache.pgsql:
added a handle field to the table.




git-svn-id: https://svn.ic-s.nl/svn/dbmail/trunk/dbmail@1970 7b491191-dbf0-0310-aff6-d879d4d69008
  • Loading branch information
aaron committed Jan 30, 2006
1 parent 9037ee0 commit 28699fa
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 176 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
@@ -1,3 +1,22 @@
2006-01-29 Aaron Stone <aaron@serendipity.cx>

* sort.h, sort.c, sortmodule.c, modules/sortsieve.c:
major work on the Sieve interface.
* sievecmd.c:
bugfixes.
* configure.in, acinclude.m4:
Added a rudimentary summary at the end.
* db.h, db.c:
added arguments to db_replycache functions, changed them to work by
days since the last reply rather than seconds, bugfixes in the
db_rename_sievescript function.
* modules/dbmysql.c, modules/dbpgsql.c, pipe.c:
change the replycache sql chunk to days rather than seconds.
* dbmail-message.h, dbmail-message.c:
added envelope sender's address (more to do on this though).
* sql/postgresql/add_replycache.pgsql:
added a handle field to the table.

2006-01-24 Aaron Stone <aaron@serendipity.cx>

* dbmail-user.c:
Expand Down
15 changes: 15 additions & 0 deletions acinclude.m4
Expand Up @@ -9,6 +9,21 @@ make your compile work without much twiddling.
])
])

dnl DBMAIL_MSG_CONFIGURE_RESULTS()
dnl
AC_DEFUN([DBMAIL_MSG_CONFIGURE_RESULTS], [dnl
AC_MSG_RESULT([
MYSQL: $MYSQLINC
PGSQL: $PGSQLINC
SQLITE: $SQLITEINC
SIEVE: $SIEVEINC
LDAP: $LDAPINC
SHARED: $enable_shared
STATIC: $enable_static
])
])


dnl DBMAIL_BOTH_SQL_CHECK
dnl
AC_DEFUN([DBMAIL_BOTH_SQL_CHECK], [dnl
Expand Down
1 change: 1 addition & 0 deletions configure.in
Expand Up @@ -98,3 +98,4 @@ AC_PROG_LIBTOOL

AC_OUTPUT(Makefile modules/Makefile man/Makefile)

DBMAIL_MSG_CONFIGURE_RESULTS
49 changes: 35 additions & 14 deletions db.c
Expand Up @@ -563,7 +563,7 @@ int db_get_sievescript_listall(u64_t user_idnr, struct dm_list *scriptlist)
while(i < n) {
info = (struct ssinfo *)dm_malloc(sizeof(struct ssinfo));
info->name = dm_strdup(db_get_result(i, 0));
info->active = (int)db_get_result(i, 1);
info->active = db_get_result_int(i, 1);
dm_list_nodeadd(scriptlist,info,sizeof(struct ssinfo));
i++;
}
Expand All @@ -580,8 +580,19 @@ int db_rename_sievescript(u64_t user_idnr, char *scriptname, char *newname)
db_escape_string(escaped_scriptname, scriptname, strlen(scriptname));
db_escape_string(escaped_newname, newname, strlen(newname));
snprintf(query, DEF_QUERYSIZE,
"UPDATE %ssievescripts set name = '%s' "
"where owner_idnr = %llu and name = '%s'",
"SELECT COUNT(*) FROM %ssievescripts "
"WHERE owner_idnr = %llu AND name = '%s'",
DBPFX,user_idnr,escaped_newname);

if (db_query(query) == 0 && db_get_result_int(0,0) > 0) {
dm_free(escaped_scriptname);
dm_free(escaped_newname);
return -3;
}

snprintf(query, DEF_QUERYSIZE,
"UPDATE %ssievescripts SET name = '%s' "
"WHERE owner_idnr = %llu AND name = '%s'",
DBPFX,escaped_newname,user_idnr,escaped_scriptname);
dm_free(escaped_scriptname);
dm_free(escaped_newname);
Expand Down Expand Up @@ -4281,13 +4292,14 @@ int db_user_find_create(u64_t user_idnr)
return db_user_create_shadow(username, &user_idnr);
}

int db_replycache_register(const char *to, const char *from)
int db_replycache_register(const char *to, const char *from, const char *handle)
{
snprintf(query, DEF_QUERYSIZE,
"SELECT lastseen FROM %sreplycache "
"WHERE to_addr = '%s' "
"AND from_addr = '%s'",
DBPFX, to, from);
"AND from_addr = '%s' "
"AND handle = '%s' ",
DBPFX, to, from, handle);
if (db_query(query)== -1) {
trace(TRACE_ERROR, "%s,%s: query failed",
__FILE__, __func__);
Expand All @@ -4297,12 +4309,15 @@ int db_replycache_register(const char *to, const char *from)
if (db_num_rows() > 0) {
snprintf(query, DEF_QUERYSIZE,
"UPDATE %sreplycache SET lastseen = %s "
"WHERE to_addr = '%s' AND from_addr = '%s'", DBPFX, db_get_sql(SQL_CURRENT_TIMESTAMP),
to, from);
"WHERE to_addr = '%s' AND from_addr = '%s' "
"AND handle = '%s'",
DBPFX, db_get_sql(SQL_CURRENT_TIMESTAMP),
to, from, handle);
} else {
snprintf(query, DEF_QUERYSIZE,
"INSERT INTO %sreplycache (to_addr, from_addr, lastseen) "
"VALUES ('%s','%s', %s)", DBPFX, to, from, db_get_sql(SQL_CURRENT_TIMESTAMP));
"INSERT INTO %sreplycache (to_addr, from_addr, handle, lastseen) "
"VALUES ('%s','%s','%s', %s)",
DBPFX, to, from, handle, db_get_sql(SQL_CURRENT_TIMESTAMP));
}

db_free_result();
Expand All @@ -4317,20 +4332,26 @@ int db_replycache_register(const char *to, const char *from)

}

#define REPLYCACHE_TIMEOUT 3600*24*7
int db_replycache_validate(const char *to, const char *from)
/* Returns DM_SUCCESS if the (to, from) pair hasn't been seen in days.
*/
int db_replycache_validate(const char *to, const char *from,
const char *handle, int days)
{
GString *tmp = g_string_new("");
g_string_printf(tmp, db_get_sql(SQL_REPLYCACHE_EXPIRE), REPLYCACHE_TIMEOUT);
g_string_printf(tmp, db_get_sql(SQL_REPLYCACHE_EXPIRE), days);
snprintf(query, DEF_QUERYSIZE,
"SELECT lastseen FROM %sreplycache "
"WHERE to_addr = '%s' AND from_addr = '%s' "
"AND lastseen > (%s)", DBPFX, to, from, tmp->str);
"AND handle = '%s' AND lastseen > (%s)",
DBPFX, to, from, handle, tmp->str);
g_string_free(tmp, TRUE);

if (db_query(query) == -1) {
trace(TRACE_ERROR, "%s,%s: query failed",
__FILE__, __func__);
return DM_EQUERY;
}

if (db_num_rows() > 0) {
db_free_result();
return DM_EGENERAL;
Expand Down
6 changes: 4 additions & 2 deletions db.h
Expand Up @@ -1314,8 +1314,10 @@ int db_user_rename(u64_t user_idnr, const char *new_name);
int db_change_mailboxsize(u64_t user_idnr, u64_t new_size);

/* auto-reply cache */
int db_replycache_register(const char *to, const char *from);
int db_replycache_validate(const char *to, const char *from);
int db_replycache_register(const char *to, const char *from,
const char *handle);
int db_replycache_validate(const char *to, const char *from,
const char *handle, int days);

/* get driver specific SQL snippets */
const char * db_get_sql(sql_fragment_t frag);
Expand Down
15 changes: 14 additions & 1 deletion dbmail-message.c
Expand Up @@ -152,7 +152,8 @@ struct DbmailMessage * dbmail_message_new(void)

self->internal_date = g_string_new("");

self->header_dict = g_hash_table_new_full((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal, (GDestroyNotify)g_free, NULL);
self->header_dict = g_hash_table_new_full((GHashFunc)g_str_hash,
(GEqualFunc)g_str_equal, (GDestroyNotify)g_free, NULL);

dbmail_message_set_class(self, DBMAIL_MESSAGE);

Expand Down Expand Up @@ -381,6 +382,18 @@ gchar * dbmail_message_get_internal_date(const struct DbmailMessage *self)
return NULL;
}

void dbmail_message_set_envelope(const struct DbmailMessage *self, char *envelope)
{
if (envelope)
g_string_printf(self->envelope, "%s", envelope);
}

gchar * dbmail_message_get_envelope(const struct DbmailMessage *self)
{
if (self->envelope->len > 0)
return self->envelope->str;
return NULL;
}

void dbmail_message_set_header(struct DbmailMessage *self, const char *header, const char *value)
{
Expand Down
5 changes: 4 additions & 1 deletion dbmail-message.h
Expand Up @@ -64,6 +64,7 @@ struct DbmailMessage {
u64_t id;
u64_t physid;
GString *internal_date;
GString *envelope;
enum DBMAIL_MESSAGE_CLASS klass;
GByteArray *raw;
GMimeObject *content;
Expand Down Expand Up @@ -101,6 +102,9 @@ gchar * dbmail_message_get_internal_date(const struct DbmailMessage *self);
int dbmail_message_set_class(struct DbmailMessage *self, int klass);
int dbmail_message_get_class(const struct DbmailMessage *self);

void dbmail_message_set_envelope(const struct DbmailMessage *self, char *envelope);
gchar * dbmail_message_get_envelope(const struct DbmailMessage *self);

gchar * dbmail_message_to_string(const struct DbmailMessage *self);
gchar * dbmail_message_hdrs_to_string(const struct DbmailMessage *self);
gchar * dbmail_message_body_to_string(const struct DbmailMessage *self);
Expand Down Expand Up @@ -129,7 +133,6 @@ void dbmail_message_cache_subjectfield(const struct DbmailMessage *self);
void dbmail_message_cache_referencesfield(const struct DbmailMessage *self);

GList * dbmail_message_get_structure(const struct DbmailMessage *self, gboolean extension);
GList * dbmail_message_get_envelope(const struct DbmailMessage *self);
/*
* destructor
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/dbmysql.c
Expand Up @@ -44,7 +44,7 @@ const char * db_get_sql(sql_fragment_t frag)
return "CURRENT_TIMESTAMP";
break;
case SQL_REPLYCACHE_EXPIRE:
return "NOW() - INTERVAL %d SECOND";
return "NOW() - INTERVAL %d DAY";
break;
}
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion modules/dbpgsql.c
Expand Up @@ -51,7 +51,7 @@ const char * db_get_sql(sql_fragment_t frag)
return "CURRENT_TIMESTAMP";
break;
case SQL_REPLYCACHE_EXPIRE:
return "NOW() - INTERVAL '%d SECOND'";
return "NOW() - INTERVAL '%d DAY'";
break;
}
return NULL;
Expand Down

0 comments on commit 28699fa

Please sign in to comment.