/* 6.3.6. SUBSCRIBE Command Arguments: mailbox Responses: no specific responses for this command Result: OK - subscribe completed NO - subscribe failure: can't subscribe to that name BAD - command unknown or arguments invalid */ int imap4d_subscribe (struct imap4d_session *session, struct imap4d_command *command, imap4d_tokbuf_t tok) { int rc; char *name; mu_property_t prop; if (imap4d_tokbuf_argc (tok) != 3) return io_completion_response (command, RESP_BAD, "Invalid arguments"); name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); prop = open_subscription (); if (!prop) return io_completion_response (command, RESP_NO, "Cannot subscribe"); rc = mu_property_set_value (prop, name, "", 1); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_property_set_value", name, rc); else { rc = mu_property_save (prop); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_property_save", NULL, rc); } mu_property_destroy (&prop); if (rc) return io_completion_response (command, RESP_NO, "Cannot subscribe"); return io_completion_response (command, RESP_OK, "Completed"); }
static int test_and_update_prop (mu_property_t prop, const char *from, time_t now, unsigned int days, mu_sieve_machine_t mach) { const char *result; char *timebuf; time_t last; int rc = mu_property_sget_value (prop, from, &result); switch (rc) { case MU_ERR_NOENT: break; case 0: if (days == 0) return 1; last = (time_t) strtoul (result, NULL, 0); if (last + (24 * 60 * 60 * days) > now) return 1; break; default: mu_sieve_error (mach, "%lu: mu_property_sget_value: %s", (unsigned long) mu_sieve_get_message_num (mach), mu_strerror (rc)); return -1; } rc = mu_asprintf (&timebuf, "%lu", (unsigned long) now); if (rc) { mu_sieve_error (mach, "%lu: mu_asprintf: %s", (unsigned long) mu_sieve_get_message_num (mach), mu_strerror (rc)); return -1; } rc = mu_property_set_value (prop, from, timebuf, 1); free (timebuf); if (rc) { mu_sieve_error (mach, "%lu: mu_property_set_value: %s", (unsigned long) mu_sieve_get_message_num (mach), mu_strerror (rc)); return -1; } rc = mu_property_save (prop); if (rc) { mu_sieve_error (mach, "%lu: mu_property_save: %s", (unsigned long) mu_sieve_get_message_num (mach), mu_strerror (rc)); return -1; } return 0; }