[svn-commits] mmichelson: branch mmichelson/imap_consistency r132820 - /team/mmichelson/ima...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 22 18:44:51 CDT 2008


Author: mmichelson
Date: Tue Jul 22 18:44:51 2008
New Revision: 132820

URL: http://svn.digium.com/view/asterisk?view=rev&rev=132820
Log:
Rid the code of a ton of redundant logic. Use the
create_vm_state_from_user function instead of replicating
the same code everywhere.


Modified:
    team/mmichelson/imap_consistency/apps/app_voicemail.c

Modified: team/mmichelson/imap_consistency/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency/apps/app_voicemail.c?view=diff&rev=132820&r1=132819&r2=132820
==============================================================================
--- team/mmichelson/imap_consistency/apps/app_voicemail.c (original)
+++ team/mmichelson/imap_consistency/apps/app_voicemail.c Tue Jul 22 18:44:51 2008
@@ -131,7 +131,7 @@
 static char *get_user_by_mailbox(char *mailbox);
 static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive);
 static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, int interactive);
-static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu, char *mailbox);
+static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu);
 static void vmstate_insert(struct vm_state *vms);
 static void vmstate_delete(struct vm_state *vms);
 static void set_update(MAILSTREAM * stream);
@@ -1638,18 +1638,6 @@
 #ifdef IMAP_STORAGE
 static int imap_retrieve_file(const char *dir, const int msgnum, const struct ast_vm_user *vmu)
 {
-	/* Let's break this into partz */
-
-	/* Part 1: Get the voice message from the IMAP server
-	 * The logic for this can almost be cut and pasted from
-	 * the IMAP version of play_message
-	 *
-	 * Part 2: Get the headers that describe the message
-	 * and place them in an accompanying text file. Most of
-	 * this can also be lifted from the play_message function.
-	 * 
-	 */
-
 	BODY *body;
 	char *header_content;
 	char *attachedfilefmt;
@@ -2649,21 +2637,10 @@
 	}
 
 	if (!vms_p) {
-		if (option_debug > 2)
-			ast_log (LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser);
-		if (!(vms_p = ast_calloc(1, sizeof(*vms_p)))) {
+		if (!(vms_p = create_vm_state_from_user(vmu))) {
+			ast_log(LOG_WARNING, "Unable to allocate space for new vm_state!\n");
 			return -1;
 		}
-		ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser));
-		ast_copy_string(vms_p->username, mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
-		vms_p->mailstream = NIL; /* save for access from interactive entry point */
-		if (option_debug > 2)
-			ast_log (LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
-		vms_p->updated = 1;
-		/* set mailbox to INBOX! */
-		ast_copy_string(vms_p->curbox, mbox(fold), sizeof(vms_p->curbox));
-		init_vm_state(vms_p);
-		vmstate_insert(vms_p);
 	}
 	ret = init_mailstream(vms_p, fold);
 	if (!vms_p->mailstream) {
@@ -3187,20 +3164,10 @@
 		if (!(vms = get_vm_state_by_mailbox(ext,0))) {
 		/*It is possible under certain circumstances that inboxcount did not create a vm_state when it was needed. This is a catchall which will
 		 * rarely be used*/
-			if (!(vms = ast_calloc(1, sizeof(*vms)))) {
+			if (!(vms = create_vm_state_from_user(vmu))) {
 				ast_log(LOG_ERROR, "Couldn't allocate necessary space\n");
 				return -1;
 			}
-			ast_copy_string(vms->imapuser, vmu->imapuser, sizeof(vms->imapuser));
-			ast_copy_string(vms->username, ext, sizeof(vms->username));
-			vms->mailstream = NIL;
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "Copied %s to %s\n", vmu->imapuser, vms->imapuser);
-			vms->updated=1;
-			ast_copy_string(vms->curbox, mbox(0), sizeof(vms->curbox));
-			init_vm_state(vms);
-			vmstate_insert(vms);
-			vms = get_vm_state_by_mailbox(ext,0);
 		}
 		vms->newmessages++;
 		/* here is a big difference! We add one to it later */
@@ -4343,7 +4310,7 @@
 				/* get destination mailbox */
 				dstvms = get_vm_state_by_mailbox(vmtmp->mailbox,0);
 				if (!dstvms) {
-					dstvms = create_vm_state_from_user(vmtmp, vmtmp->mailbox);
+					dstvms = create_vm_state_from_user(vmtmp);
 				}
 				if (dstvms) {
 					init_mailstream(dstvms, 0);
@@ -8768,7 +8735,7 @@
 	}
 }
 
-static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu, char *mailbox)
+static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu)
 {
 	struct vm_state *vms_p;
 
@@ -8777,7 +8744,7 @@
 	if (!(vms_p = ast_calloc(1, sizeof(*vms_p))))
 		return NULL;
 	ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser));
-	ast_copy_string(vms_p->username, mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
+	ast_copy_string(vms_p->username, vmu->mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
 	vms_p->mailstream = NIL; /* save for access from interactive entry point */
 	if (option_debug > 4)
 		ast_log(LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);




More information about the svn-commits mailing list