expire-env.c revision e07bf3772a2bc075de4915ad0961beb8d083c22d
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen ARRAY_DEFINE(expire_boxes, struct expire_box);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic void expire_env_parse(struct expire_env *env, const char *str,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen char *const *names;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen unsigned int len;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen len = str_array_length((const char *const *)names);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen p_array_init(&env->expire_boxes, env->pool, len / 2);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen i_fatal("expire: Missing expire days for mailbox '%s'",
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen /* FIXME: hardcoded separator isn't very good */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen box.glob = imap_match_init(env->pool, box.pattern, TRUE, '/');
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen box.expire_secs = strtoul(names[1], NULL, 10) * 3600 * 24;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstruct expire_env *expire_env_init(const char *expunges, const char *altmoves)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen pool = pool_alloconly_create("Expire pool", 512);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen expire_env_parse(env, expunges, EXPIRE_TYPE_EXPUNGE);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen expire_env_parse(env, altmoves, EXPIRE_TYPE_ALTMOVE);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenbool expire_box_find(struct expire_env *env, const char *name,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen unsigned int i, count;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen unsigned int secs, expunge_min = 0, altmove_min = 0;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen expire_boxes = array_get(&env->expire_boxes, &count);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen for (i = 0; i < count; i++) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (imap_match(expire_boxes[i].glob, name) == IMAP_MATCH_YES) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenunsigned int expire_box_find_min_secs(struct expire_env *env, const char *name,