[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r367414 - /team/mmichelson/t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 23 13:19:16 CDT 2012


Author: mmichelson
Date: Wed May 23 13:19:10 2012
New Revision: 367414

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367414
Log:
Add support for updating a message ID when using IMAP storage.

IMAP messages, once delivered, cannot be updated. Instead, the
method used here is to delete the message and then store it again
with the message ID added on.

In my next update, I'm going to see if I can preserve the "read" vs.
"unread" status of the message when storing it so that messages don't
appear mistakenly as unread.


Modified:
    team/mmichelson/trunk-digiumphones/apps/app_voicemail.c

Modified: team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/apps/app_voicemail.c?view=diff&rev=367414&r1=367413&r2=367414
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Wed May 23 13:19:10 2012
@@ -496,6 +496,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(const char *dir, const char *mailboxuser, const char *mailboxcontext, int msgnum, struct ast_channel *chan, struct ast_vm_user *vmu, char *fmt, int duration, struct vm_state *vms, const char *flag, const char *msg_id);
+static void vm_imap_update_msg_id(char *dir, int msgnum, const char *msg_id, struct ast_vm_user *vmu, struct ast_config *msg_cfg);
 static void update_messages_by_imapuser(const char *user, unsigned long number);
 static int vm_delete(char *file);
 
@@ -842,6 +843,7 @@
 #define RENAME(a,b,c,d,e,f,g,h) (rename_file(a,b,c,d,e,f))
 #define COPY(a,b,c,d,e,f,g,h) (copy_file(a,b,c,d,e,f))
 #define DELETE(a,b,c,d) (delete_file(a,b))
+#define UPDATE_MSG_ID(a, b, c, d, e) (odbc_update_msg_id((a), (b), (c)))
 #else
 #ifdef IMAP_STORAGE
 #define DISPOSE(a,b) (imap_remove_file(a,b))
@@ -851,6 +853,7 @@
 #define RENAME(a,b,c,d,e,f,g,h) (rename_file(g,h));
 #define COPY(a,b,c,d,e,f,g,h) (copy_file(g,h));
 #define DELETE(a,b,c,d) (vm_imap_delete(a,b,d))
+#define UPDATE_MSG_ID(a, b, c, d, e) (vm_imap_update_msg_id((a), (b), (c), (d), (e)))
 #else
 #define RETRIEVE(a,b,c,d)
 #define DISPOSE(a,b)
@@ -859,6 +862,7 @@
 #define RENAME(a,b,c,d,e,f,g,h) (rename_file(g,h));
 #define COPY(a,b,c,d,e,f,g,h) (copy_plain_file(g,h)); 
 #define DELETE(a,b,c,d) (vm_delete(c))
+#define UPDATE_MSG_ID(a, b, c, d, e)
 #endif
 #endif
 
@@ -1938,6 +1942,55 @@
 	ast_mutex_unlock(&vms->lock);
 }
 
+static void vm_imap_update_msg_id(char *dir, int msgnum, const char *msg_id, struct ast_vm_user *vmu, struct ast_config *msg_cfg)
+{
+	struct ast_channel *chan;
+	char *cid;
+	char *cid_name;
+	char *cid_num;
+	struct vm_state *vms;
+	const char *duration_str;
+	int duration = 0;
+
+	chan = ast_dummy_channel_alloc();
+	if (!chan) {
+		return;
+	}
+
+	vms = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 0);
+	if (!vms) {
+		chan = ast_channel_unref(chan);
+		return;
+	}
+
+	cid = ast_strdupa(ast_variable_retrieve(msg_cfg, "message", "callerid"));
+
+	if (!ast_strlen_zero(cid)) {
+		ast_callerid_parse(cid, &cid_name, &cid_num);
+		ast_party_caller_init(ast_channel_caller(chan));
+		if (!ast_strlen_zero(cid_name)) {
+			ast_channel_caller(chan)->id.name.valid = 1;
+			ast_channel_caller(chan)->id.name.str = ast_strdup(cid_name);
+		}
+		if (!ast_strlen_zero(cid_num)) {
+			ast_channel_caller(chan)->id.number.valid = 1;
+			ast_channel_caller(chan)->id.number.str = ast_strdup(cid_num);
+		}
+	}
+
+	duration_str = ast_variable_retrieve(msg_cfg, "message", "duration");
+	
+	if (!ast_strlen_zero(duration_str)) {
+		sscanf(duration_str, "%30d", &duration);
+	}
+
+	vm_imap_delete(dir, msgnum, vmu);
+	imap_store_file(dir, vmu->mailbox, vmu->context, msgnum, chan, vmu, vmfmts,
+			duration, vms, ast_variable_retrieve(msg_cfg, "message", "flag"), msg_id);
+
+	ast_channel_unref(chan);
+}
+
 static int imap_retrieve_greeting(const char *dir, const int msgnum, struct ast_vm_user *vmu)
 {
 	struct vm_state *vms_p;
@@ -11386,7 +11439,7 @@
 	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
 }
 
-static int add_message_id(struct ast_config *msg_cfg, char *dir, int msg, char *filename, char *id, size_t id_size)
+static int add_message_id(struct ast_config *msg_cfg, char *dir, int msg, char *filename, char *id, size_t id_size, struct ast_vm_user *vmu)
 {
 	struct ast_variable *var;
 	struct ast_category *cat;
@@ -11411,9 +11464,7 @@
 		return -1;
 	}
 
-#ifdef ODBC_STORAGE
-	odbc_update_msg_id(dir, msg, id);
-#endif
+	UPDATE_MSG_ID(dir, msg, id, vmu, msg_cfg);
 	return 0;
 }
 
@@ -14671,7 +14722,7 @@
 			 */
 			char id[33];
 			if (!(add_message_id(msg_cfg, vms->curdir, vms->curmsg,
-							filename, id, sizeof(id)))) {
+							filename, id, sizeof(id), vmu))) {
 				ast_string_field_set(msg_snapshot, msg_id, id);
 			} else {
 				ast_log(LOG_WARNING, "Unable to create a message ID for message %s/%d\n", vms->curdir, vms->curmsg);




More information about the asterisk-commits mailing list