Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 90048) +++ apps/app_voicemail.c (working copy) @@ -145,6 +145,7 @@ static void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota); static void imap_mailbox_name(char *spec, size_t len, struct vm_state *vms, int box, int target); static int imap_store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum, struct ast_channel *chan, struct ast_vm_user *vmu, char *fmt, int duration, struct vm_state *vms); +static void check_quota(struct vm_state *vms, char *mailbox); static void update_messages_by_imapuser(const char *user, unsigned long number); static int imap_remove_file (char *dir, int msgnum); @@ -3180,11 +3181,21 @@ pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", "IMAP_STORAGE"); /* Check if mailbox is full */ + check_quota(vms, "INBOX"); if (vms->quota_limit && vms->quota_usage >= vms->quota_limit) { ast_debug(1, "*** QUOTA EXCEEDED!! %u >= %u\n", vms->quota_usage, vms->quota_limit); ast_play_and_wait(chan, "vm-mailboxfull"); return -1; } + ast_debug(3, "Checking message number quota - mailbox has %d messages, maximum is set to %d\n",msgnum,vmu->maxmsg); + if (msgnum >= vmu->maxmsg) { + res = ast_streamfile(chan, "vm-mailboxfull", chan->language); + if (!res) + res = ast_waitstream(chan, ""); + ast_log(LOG_WARNING, "No more messages possible\n"); + pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED"); + goto leave_vm_out; + } /* here is a big difference! We add one to it later */ ast_debug(3, "Messagecount set to %d\n",msgnum); @@ -4958,7 +4969,6 @@ SEARCHPGM *pgm; SEARCHHEADER *hdr; int ret; - char dbox[256]; ast_copy_string(vms->imapuser,vmu->imapuser, sizeof(vms->imapuser)); ast_debug(3,"Before init_mailstream, user is %s\n",vmu->imapuser); @@ -4968,10 +4978,11 @@ return -1; } - /* Check Quota (here for now to test) */ - mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota); - imap_mailbox_name(dbox, sizeof(dbox), vms, box, 1); - imap_getquotaroot(vms->mailstream, dbox); + /* Check Quota */ + if (box == 0) { + ast_debug(3,"Mailbox name set to: %s, about to check quotas\n",mbox(box)); + check_quota(vms,(char *)mbox(box)); + } pgm = mail_newsearchpgm(); @@ -7021,6 +7032,11 @@ ast_debug(1, "*** QUOTA EXCEEDED!!\n"); cmd = ast_play_and_wait(chan, "vm-mailboxfull"); } + ast_debug(3, "Checking quotas: User has %d messages and limit is %d.\n",(vms.newmessages + vms.oldmessages),vmu->maxmsg); + if ((vms.newmessages + vms.oldmessages) >= vmu->maxmsg) { + ast_log(LOG_WARNING, "No more messages possible. User has %d messages and limit is %d.\n",(vms.newmessages + vms.oldmessages),vmu->maxmsg); + cmd = ast_play_and_wait(chan, "vm-mailboxfull"); + } #endif if (play_auto) { cmd = '1'; @@ -9633,6 +9649,17 @@ mail_list(stream, tmp, "*"); } +/* Check Quota for user */ +static void check_quota(struct vm_state *vms, char *mailbox) { + mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota); + ast_debug(3,"Mailbox name set to: %s, about to check quotas\n",mailbox); + if (vms && vms->mailstream != NULL) { + imap_getquotaroot(vms->mailstream, mailbox); + } else { + ast_log(LOG_WARNING,"Mailstream not available for mailbox: %s\n",mailbox); + } +} + #endif /* IMAP_STORAGE */ /* This is a workaround so that menuselect displays a proper description