static int mail_sieve_user_init (struct mail_user *user, struct sieve_storage **svstorage_r) { struct sieve_mail_user *suser = SIEVE_USER_CONTEXT(user); enum sieve_storage_flags storage_flags = SIEVE_STORAGE_FLAG_READWRITE | SIEVE_STORAGE_FLAG_SYNCHRONIZING; struct sieve_environment svenv; i_assert( suser != NULL ); if ( suser->svinst != NULL ) { *svstorage_r = suser->sieve_storage; return suser->sieve_storage != NULL ? 1 : 0; } /* Delayed initialization of sieve storage until it's actually needed */ memset(&svenv, 0, sizeof(svenv)); svenv.username = user->username; (void)mail_user_get_home(user, &svenv.home_dir); svenv.base_dir = user->set->base_dir; svenv.flags = SIEVE_FLAG_HOME_RELATIVE; suser->svinst = sieve_init(&svenv, &mail_sieve_callbacks, user, user->mail_debug); suser->sieve_storage = sieve_storage_create_main (suser->svinst, user, storage_flags, NULL); *svstorage_r = suser->sieve_storage; return suser->sieve_storage != NULL ? 1 : 0; }
void managesieve_capabilities_dump(void) { const struct plugin_settings *global_plugin_settings; struct sieve_environment svenv; struct sieve_instance *svinst; const char *notify_cap; /* Read plugin settings */ global_plugin_settings = plugin_settings_read(); /* Initialize Sieve engine */ memset((void*)&svenv, 0, sizeof(svenv)); svenv.home_dir = "/tmp"; svinst = sieve_init (&svenv, &sieve_callbacks, (void *) global_plugin_settings, FALSE); /* Dump capabilities */ notify_cap = sieve_get_capabilities(svinst, "notify"); if ( notify_cap == NULL ) printf("SIEVE: %s\n", sieve_get_capabilities(svinst, NULL)); else printf("SIEVE: %s, NOTIFY: %s\n", sieve_get_capabilities(svinst, NULL), sieve_get_capabilities(svinst, "notify")); }
static int doveadm_sieve_cmd_run (struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) { struct doveadm_sieve_cmd_context *ctx = (struct doveadm_sieve_cmd_context *)_ctx; struct sieve_environment svenv; enum sieve_error error; int ret; memset((void*)&svenv, 0, sizeof(svenv)); svenv.username = user->username; (void)mail_user_get_home(user, &svenv.home_dir); svenv.base_dir = user->set->base_dir; svenv.flags = SIEVE_FLAG_HOME_RELATIVE; ctx->svinst = sieve_init (&svenv, &sieve_callbacks, (void *)ctx, user->mail_debug); ctx->storage = sieve_storage_create_main (ctx->svinst, user, SIEVE_STORAGE_FLAG_READWRITE, &error); if ( ctx->storage == NULL ) { switch ( error ) { case SIEVE_ERROR_NOT_FOUND: i_error("Failed to open Sieve storage: Sieve disabled for user"); break; default: i_error("Failed to open Sieve storage."); } doveadm_sieve_cmd_failed_error(ctx, error); ret = -1; } else { i_assert( ctx->v.run != NULL ); ret = ctx->v.run(ctx); sieve_storage_unref(&ctx->storage); } sieve_deinit(&ctx->svinst); return ret; }
struct imap_sieve *imap_sieve_init(struct mail_user *user, const struct lda_settings *lda_set) { struct sieve_environment svenv; struct imap_sieve *isieve; bool debug = user->mail_debug; pool_t pool; pool = pool_alloconly_create("imap_sieve", 256); isieve = p_new(pool, struct imap_sieve, 1); isieve->pool = pool; isieve->user = user; isieve->lda_set = lda_set; isieve->dup_ctx = duplicate_init(user); memset(&svenv, 0, sizeof(svenv)); svenv.username = user->username; (void)mail_user_get_home(user, &svenv.home_dir); svenv.hostname = lda_set->hostname; svenv.base_dir = user->set->base_dir; svenv.flags = SIEVE_FLAG_HOME_RELATIVE; svenv.location = SIEVE_ENV_LOCATION_MS; svenv.delivery_phase = SIEVE_DELIVERY_PHASE_POST; isieve->home_dir = p_strdup(pool, svenv.home_dir); isieve->svinst = sieve_init (&svenv, &mail_sieve_callbacks, isieve, debug); isieve->ext_imapsieve = sieve_extension_replace (isieve->svinst, &imapsieve_extension, TRUE); isieve->master_ehandler = sieve_master_ehandler_create (isieve->svinst, NULL, 0); // FIXME: prefix? sieve_system_ehandler_set(isieve->master_ehandler); sieve_error_handler_accept_infolog(isieve->master_ehandler, TRUE); sieve_error_handler_accept_debuglog(isieve->master_ehandler, debug); return isieve; }
int main(int argc, char *argv[]) { sieve s; long pr, *p; int c, ix, cur = 0; if(argc < 2) { fprintf(stderr, "Usage: %s <width>\n", argv[0]); return 1; } c = atoi(argv[1]); if(c < 0) c = -c; fprintf(stderr, "%s: sieving to %d positions\n", argv[0], c); sieve_init(&s, 3, c); c = 0; while((pr = sieve_next(&s)) > 0) { ++c; } p = calloc(c, sizeof(long)); if(!p) { fprintf(stderr, "%s: out of memory after first half\n", argv[0]); sieve_clear(&s); exit(1); } fprintf(stderr, "%s: half done ... \n", argv[0]); for(ix = 0; ix < s.nbits; ix++) { if(S_ISSET(&s, ix)) { p[cur] = S_VAL(&s, ix); printf("%ld\n", p[cur]); ++cur; } } sieve_reset(&s, p[cur - 1]); fprintf(stderr, "%s: crossing off %d found primes ... \n", argv[0], cur); for(ix = 0; ix < cur; ix++) { sieve_cross(&s, p[ix]); if(!(ix % 1000)) fputc('.', stderr); } fputc('\n', stderr); free(p); fprintf(stderr, "%s: sieving again from %ld ... \n", argv[0], p[cur - 1]); c = 0; while((pr = sieve_next(&s)) > 0) { ++c; } fprintf(stderr, "%s: done!\n", argv[0]); for(ix = 0; ix < s.nbits; ix++) { if(S_ISSET(&s, ix)) { printf("%ld\n", S_VAL(&s, ix)); } } sieve_clear(&s); return 0; }
struct sieve_instance *sieve_tool_init_finish (struct sieve_tool *tool, bool init_mailstore, bool preserve_root) { enum mail_storage_service_flags storage_service_flags = MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR | MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT | MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS; struct mail_storage_service_input service_input; struct sieve_environment svenv; const char *username = tool->username; const char *homedir = tool->homedir; const char *errstr; master_service_init_finish(master_service); if ( username == NULL ) { sieve_tool_get_user_data(&username, &homedir); username = tool->username = i_strdup(username); if ( tool->homedir != NULL ) i_free(tool->homedir); tool->homedir = i_strdup(homedir); if ( preserve_root ) { storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS; } } else { storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; } if ( !init_mailstore ) storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES; memset(&service_input, 0, sizeof(service_input)); service_input.module = "mail"; service_input.service = tool->name; service_input.username = username; tool->storage_service = mail_storage_service_init (master_service, NULL, storage_service_flags); if (mail_storage_service_lookup_next (tool->storage_service, &service_input, &tool->service_user, &tool->mail_user_dovecot, &errstr) <= 0) i_fatal("%s", errstr); if ( master_service_set (master_service, "mail_full_filesystem_access=yes") < 0 ) i_unreached(); memset((void *)&svenv, 0, sizeof(svenv)); svenv.username = username; (void)mail_user_get_home(tool->mail_user_dovecot, &svenv.home_dir); svenv.hostname = my_hostdomain(); svenv.base_dir = tool->mail_user_dovecot->set->base_dir; svenv.temp_dir = tool->mail_user_dovecot->set->mail_temp_dir; svenv.location = SIEVE_ENV_LOCATION_MS; svenv.delivery_phase = SIEVE_DELIVERY_PHASE_POST; /* Initialize Sieve Engine */ if ( (tool->svinst=sieve_init (&svenv, &sieve_tool_callbacks, tool, tool->debug)) == NULL ) i_fatal("failed to initialize sieve implementation"); /* Load Sieve plugins */ if ( array_count(&tool->sieve_plugins) > 0 ) { sieve_tool_load_plugins(tool); } /* Set active Sieve extensions */ if ( tool->sieve_extensions != NULL ) { sieve_set_extensions(tool->svinst, tool->sieve_extensions); } else if ( tool->no_config ) { sieve_set_extensions(tool->svinst, NULL); } return tool->svinst; }