[asterisk-commits] mmichelson: branch mmichelson/imap_consistency r129639 - /team/mmichelson/ima...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 10 13:17:00 CDT 2008


Author: mmichelson
Date: Thu Jul 10 13:16:59 2008
New Revision: 129639

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129639
Log:
1) Add fclose() call to end of imap_retrieve_file
2) Add comment describing what may need to be done if a vm_state
   cannot be retrieved.
3) Remove the IMAP-specific play_message function and remove
   the pointless check_msgArray function too.


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=129639&r1=129638&r2=129639
==============================================================================
--- team/mmichelson/imap_consistency/apps/app_voicemail.c (original)
+++ team/mmichelson/imap_consistency/apps/app_voicemail.c Thu Jul 10 13:16:59 2008
@@ -136,7 +136,6 @@
 static void vmstate_delete(struct vm_state *vms);
 static void set_update(MAILSTREAM * stream);
 static void init_vm_state(struct vm_state *vms);
-static void check_msgArray(struct vm_state *vms);
 static void copy_msgArray(struct vm_state *dst, struct vm_state *src);
 static int save_body(BODY *body, struct vm_state *vms, char *section, char *format);
 static int make_gsm_file(char *dest, size_t len, char *imapuser, char *dir, int num);
@@ -1679,8 +1678,13 @@
 	 */
 	vms = get_vm_state_by_mailbox(vmu->mailbox, 2);
 	if (!vms) {
-		/* *sigh*, we have to create it */
-		/*XXX Do this later. */
+		/* This should not happen. If it does, then I guess we'd
+		 * need to create the vm_state, extract which mailbox to
+		 * open, and then set up the msgArray so that the correct
+		 * IMAP message could be accessed. If I have seen correctly
+		 * though, the vms should be obtainable from the vmstates list
+		 * and should have its msgArray properly set up.
+		 */
 	}
 
 	if (option_debug > 2)
@@ -1744,7 +1748,7 @@
 	fprintf(text_file_ptr, "duration=%s\n", S_OR(origtime, ""));
 	category = get_header_by_tag(header_content, "X-Asterisk-VM-Category:");
 	fprintf(text_file_ptr, "category=%s\n", S_OR(category, ""));
-
+	fclose(text_file_ptr);
 	return 0;
 }
 #endif
@@ -4657,140 +4661,6 @@
 	return res;
 }
 
-#ifdef IMAP_STORAGE
-static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms)
-{
-	BODY *body;
-	char *header_content;
-	char cid[256];
-	char context[256];
-	char origtime[32];
-	char duration[16];
-	char category[32];
-	char todir[PATH_MAX];
-	int res = 0;
-	char *attachedfilefmt;
-	char *temp;
-
-	vms->starting = 0; 
-	if (option_debug > 2)
-		ast_log (LOG_DEBUG,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
-	if (vms->msgArray[vms->curmsg] == 0) {
-		ast_log (LOG_WARNING,"Trying to access unknown message\n");
-		return -1;
-	}
-
-	/* This will only work for new messages... */
-	header_content = mail_fetchheader (vms->mailstream, vms->msgArray[vms->curmsg]);
-	/* empty string means no valid header */
-	if (ast_strlen_zero(header_content)) {
-		ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
-		return -1;
-	}
-	snprintf(todir, sizeof(todir), "%s%s/%s/tmp", VM_SPOOL_DIR, vmu->context, vmu->mailbox);
-	make_gsm_file(vms->fn, sizeof(vms->fn), vms->imapuser, todir, vms->curmsg);
-
-	mail_fetchstructure (vms->mailstream,vms->msgArray[vms->curmsg],&body);
-	
-	/* We have the body, now we extract the file name of the first attachment. */
-	if (body->nested.part && body->nested.part->next && body->nested.part->next->body.parameter->value) {
-		attachedfilefmt = ast_strdupa(body->nested.part->next->body.parameter->value);
-	} else {
-		ast_log(LOG_ERROR, "There is no file attached to this IMAP message.\n");
-		return -1;
-	}
-	
-	/* Find the format of the attached file */
-
-	strsep(&attachedfilefmt, ".");
-	if (!attachedfilefmt) {
-		ast_log(LOG_ERROR, "File format could not be obtained from IMAP message attachment\n");
-		return -1;
-	}
-	save_body(body, vms, "2", attachedfilefmt);
-
-	adsi_message(chan, vms);
-	if (!vms->curmsg)
-		res = wait_file2(chan, vms, "vm-first");	/* "First" */
-	else if (vms->curmsg == vms->lastmsg)
-		res = wait_file2(chan, vms, "vm-last");		/* "last" */
-	if (!res) {
-		res = wait_file2(chan, vms, "vm-message");	/* "message" */
-		if (vms->curmsg && (vms->curmsg != vms->lastmsg)) {
-			if (!res)
-				res = ast_say_number(chan, vms->curmsg + 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
-		}
-	}
-
-	/* Get info from headers!! */
-	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Caller-ID-Num:");
-
-	if (temp)
-		ast_copy_string(cid, temp, sizeof(cid)); 
-	else 
-		cid[0] = '\0';
-
-	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Context:");
-
-	if (temp)
-		ast_copy_string(context, temp, sizeof(context)); 
-	else
-		context[0] = '\0';
-
-	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Orig-time:");
-
-	if (temp)
-		ast_copy_string(origtime, temp, sizeof(origtime));
-	else
-		origtime[0] = '\0';
-
-	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Duration:");
-
-	if (temp)
-		ast_copy_string(duration,temp, sizeof(duration));
-	else
-		duration[0] = '\0';
-	
-	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Category:");
-	
-	if (temp)
-		ast_copy_string(category,temp, sizeof(category));
-	else
-		category[0] = '\0';
-
-	/*if (!strncasecmp("macro",context,5))  Macro names in contexts are useless for our needs */
-	/*	context = ast_variable_retrieve(msg_cfg, "message","macrocontext"); */
-	if (res == '1')
-		res = 0;
-
-	if ((!res) && !ast_strlen_zero(category)) {
-		res = play_message_category(chan, category);
-	}
-
-	if ((!res) && (ast_test_flag(vmu, VM_ENVELOPE)) && origtime[0] != '\0')
-		res = play_message_datetime(chan, vmu, origtime, "IMAP_STORAGE");
-	if ((!res) && (ast_test_flag(vmu, VM_SAYCID)) && cid[0] !='\0' && context[0] !='\0')
-		res = play_message_callerid(chan, vms, cid, context, 0);
-
-	if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)) && duration[0] != '\0')
-		res = play_message_duration(chan, vms, duration, vmu->saydurationm);
-
-	/* Allow pressing '1' to skip envelope / callerid */
-	/* if (res == '1')
-		res = 0;
-	*/
-	/*ast_config_destroy(msg_cfg);*/
-	res = 0;
-
-	if (!res) {
-		vms->heard[vms->curmsg] = 1;
-		res = wait_file(chan, vms, vms->fn);
-	}
-	DISPOSE(vms->curdir, vms->curmsg);
-	DELETE(0, 0, vms->fn);
-	return res;
-}
-#else
 static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms)
 {
 	int res = 0;
@@ -9196,14 +9066,8 @@
 				ast_log(LOG_DEBUG, "Duplicate mailbox %s, copying message info...\n",vms->username);
 			vms->newmessages = altvms->newmessages;
 			vms->oldmessages = altvms->oldmessages;
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "check_msgArray before memcpy\n");
-			check_msgArray(vms);
 			/* memcpy(vms->msgArray, altvms->msgArray, sizeof(long)*256); */
 			copy_msgArray(vms, altvms);
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "check_msgArray after memcpy\n");
-			check_msgArray(vms);
 			vms->vmArrayIndex = altvms->vmArrayIndex;
 			vms->lastmsg = altvms->lastmsg;
 			vms->curmsg = altvms->curmsg;
@@ -9298,17 +9162,6 @@
 		vms->msgArray[x] = 0;
 	}
 	ast_mutex_init(&vms->lock);
-}
-
-static void check_msgArray(struct vm_state *vms) 
-{
-	int x;
-	for (x = 0; x<256; x++) {
-		if (vms->msgArray[x]!=0) {
-			if (option_debug)
-				ast_log (LOG_DEBUG, "Item %d set to %ld\n",x,vms->msgArray[x]);
-		}
-	}
 }
 
 static void copy_msgArray(struct vm_state *dst, struct vm_state *src)




More information about the asterisk-commits mailing list