]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Better quota support for using IMAP storage voicemail
authorMark Michelson <mmichelson@digium.com>
Fri, 21 Dec 2007 20:11:34 +0000 (20:11 +0000)
committerMark Michelson <mmichelson@digium.com>
Fri, 21 Dec 2007 20:11:34 +0000 (20:11 +0000)
(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/branches/1.4@94540 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c

index d7c064405af34c2d9848a529cc4c7c640d813946..af446e2818bd2912489f1ddcc4fa2017b1643d6f 100644 (file)
@@ -133,6 +133,7 @@ static void get_mailbox_delimiter(MAILSTREAM *stream);
 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 int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box);
 struct vmstate {
        struct vm_state *vms;
@@ -3007,12 +3008,24 @@ 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) {
                        if(option_debug)
                                ast_log(LOG_DEBUG, "*** QUOTA EXCEEDED!! %u >= %u\n", vms->quota_usage, vms->quota_limit);
                        ast_play_and_wait(chan, "vm-mailboxfull");
                        return -1;
                }
+               if(option_debug > 2)
+                       ast_log(LOG_DEBUG, "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;
+               }
+
                /* 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);
@@ -4735,7 +4748,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));
        if(option_debug > 2)
@@ -4746,6 +4758,13 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box)
                return -1;
        }
 
+       /* Check Quota */
+       if  (box == 0)  {
+               if (option_debug > 2)
+                       ast_log(LOG_DEBUG, "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... */
@@ -6572,6 +6591,12 @@ static int vm_execmain(struct ast_channel *chan, void *data)
                                ast_log(LOG_DEBUG, "*** QUOTA EXCEEDED!!\n");
                        cmd = ast_play_and_wait(chan, "vm-mailboxfull");
                }
+               if (option_debug > 2)
+                       ast_log(LOG_DEBUG, "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';
@@ -9003,6 +9028,18 @@ 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);
+       if (option_debug > 2)
+               ast_log(LOG_DEBUG, "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