Merged revisions 94540 via svnmerge from
authorMark Michelson <mmichelson@digium.com>
Fri, 21 Dec 2007 20:18:26 +0000 (20:18 +0000)
committerMark Michelson <mmichelson@digium.com>
Fri, 21 Dec 2007 20:18:26 +0000 (20:18 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r94540 | mmichelson | 2007-12-21 14:11:34 -0600 (Fri, 21 Dec 2007) | 8 lines

Better quota support for using IMAP storage voicemail

(closes issue #11415, reported by jaroth)
(closes issue #11152, reported by selsky)

Patch provided by jaroth

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94542 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c

index 8fb188e..8c87da3 100644 (file)
@@ -156,6 +156,8 @@ static void update_messages_by_imapuser(const char *user, unsigned long number);
 static int imap_remove_file (char *dir, int msgnum);
 static int imap_retrieve_file (char *dir, int msgnum, const char *mailbox, char *context);
 static int imap_delete_old_greeting (char *dir, struct vm_state *vms);
+static void check_quota(struct vm_state *vms, char *mailbox);
+static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box);
 struct vmstate {
        struct vm_state *vms;
        AST_LIST_ENTRY(vmstate) list;
@@ -3193,13 +3195,19 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
                pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", "IMAP_STORAGE");
 
                /* Check if mailbox is full */
+               check_quota(vms, imapfolder);
                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;
                }
-               /* here is a big difference! We add one to it later */
-               ast_debug(3, "Messagecount set to %d\n",msgnum);
+               
+               /* Check if we have exceeded maxmsg */
+               if (msgnum >= vmu->maxmsg) {
+                       ast_log(LOG_WARNING, "Unable to leave message since we will exceed the maximum number of messages allowed (%u > %u)\n", msgnum, vmu->maxmsg);
+                       ast_play_and_wait(chan, "vm-mailboxfull");
+                       return -1;
+               }
 
 #else
                if (count_messages(vmu, dir) >= vmu->maxmsg) {
@@ -4969,7 +4977,6 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box)
        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);
@@ -4984,6 +4991,12 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box)
        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();
 
        /* Check IMAP folder for Asterisk messages only... */
@@ -7033,6 +7046,11 @@ static int vm_execmain(struct ast_channel *chan, void *data)
                        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';
@@ -9690,6 +9708,17 @@ static void get_mailbox_delimiter(MAILSTREAM *stream) {
        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