[asterisk-commits] jrothenberger: branch jrothenberger/asterisk-urgent r99078 - in /team/jrothen...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 18 14:47:50 CST 2008


Author: jrothenberger
Date: Fri Jan 18 14:47:50 2008
New Revision: 99078

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99078
Log: (empty)

Modified:
    team/jrothenberger/asterisk-urgent/   (props changed)
    team/jrothenberger/asterisk-urgent/Makefile
    team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
    team/jrothenberger/asterisk-urgent/channels/chan_iax2.c
    team/jrothenberger/asterisk-urgent/channels/chan_sip.c
    team/jrothenberger/asterisk-urgent/channels/chan_skinny.c
    team/jrothenberger/asterisk-urgent/channels/chan_unistim.c
    team/jrothenberger/asterisk-urgent/include/asterisk/app.h
    team/jrothenberger/asterisk-urgent/main/app.c
    team/jrothenberger/asterisk-urgent/main/manager.c

Propchange: team/jrothenberger/asterisk-urgent/
------------------------------------------------------------------------------
--- automerge-email (original)
+++ automerge-email Fri Jan 18 14:47:50 2008
@@ -1,1 +1,1 @@
-jar at onebiztone.com
+*

Modified: team/jrothenberger/asterisk-urgent/Makefile
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/Makefile?view=diff&rev=99078&r1=99077&r2=99078
==============================================================================
--- team/jrothenberger/asterisk-urgent/Makefile (original)
+++ team/jrothenberger/asterisk-urgent/Makefile Fri Jan 18 14:47:50 2008
@@ -132,7 +132,7 @@
   ASTVARRUNDIR=/var/run/asterisk
   ASTMANDIR=/opt/asterisk/man
 else
-  ASTETCDIR=$(sysconfdir)/asterisk
+  ASTETCDIR=/usr/local/etc/asterisk
   ASTLIBDIR=$(libdir)/asterisk
   ASTHEADERDIR=$(includedir)/asterisk
   ASTBINDIR=$(bindir)

Modified: team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/apps/app_voicemail.c?view=diff&rev=99078&r1=99077&r2=99078
==============================================================================
--- team/jrothenberger/asterisk-urgent/apps/app_voicemail.c (original)
+++ team/jrothenberger/asterisk-urgent/apps/app_voicemail.c Fri Jan 18 14:47:50 2008
@@ -150,14 +150,14 @@
 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 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, char *flag);
 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);
+static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box, int urgent);
 struct vmstate {
 	struct vm_state *vms;
 	AST_LIST_ENTRY(vmstate) list;
@@ -240,7 +240,9 @@
 	OPT_RECORDGAIN =       (1 << 3),
 	OPT_PREPEND_MAILBOX =  (1 << 4),
 	OPT_AUTOPLAY =         (1 << 6),
-	OPT_DTMFEXIT =         (1 << 7),
+	OPT_MESSAGE_URGENT =   (1 << 7),
+	OPT_MESSAGE_PRIORITY = (1 << 8)
+	OPT_DTMFEXIT =         (1 << 9),
 } vm_option_flags;
 
 enum {
@@ -259,6 +261,8 @@
 	AST_APP_OPTION_ARG('d', OPT_DTMFEXIT, OPT_ARG_DTMFEXIT),
 	AST_APP_OPTION('p', OPT_PREPEND_MAILBOX),
 	AST_APP_OPTION_ARG('a', OPT_AUTOPLAY, OPT_ARG_PLAYFOLDER),
+	AST_APP_OPTION('U', OPT_MESSAGE_URGENT),
+	AST_APP_OPTION('P', OPT_MESSAGE_PRIORITY)
 });
 
 static int load_config(int reload);
@@ -412,6 +416,7 @@
 	int lastmsg;
 	int newmessages;
 	int oldmessages;
+	int urgentmessages;
 	int starting;
 	int repeats;
 #ifdef IMAP_STORAGE
@@ -433,7 +438,7 @@
 static char odbc_table[80];
 #define RETRIEVE(a,b,c,d) retrieve_file(a,b)
 #define DISPOSE(a,b) remove_file(a,b)
-#define STORE(a,b,c,d,e,f,g,h,i) store_file(a,b,c,d)
+#define STORE(a,b,c,d,e,f,g,h,i,j) store_file(a,b,c,d)
 #define EXISTS(a,b,c,d) (message_exists(a,b))
 #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))
@@ -442,7 +447,7 @@
 #ifdef IMAP_STORAGE
 #define RETRIEVE(a,b,c,d) (imap_retrieve_file(a,b,c,d ))
 #define DISPOSE(a,b) (imap_remove_file(a,b))
-#define STORE(a,b,c,d,e,f,g,h,i) (imap_store_file(a,b,c,d,e,f,g,h,i))
+#define STORE(a,b,c,d,e,f,g,h,i,j) (imap_store_file(a,b,c,d,e,f,g,h,i,j))
 #define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
 #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));
@@ -451,7 +456,7 @@
 #else
 #define RETRIEVE(a,b,c,d)
 #define DISPOSE(a,b)
-#define STORE(a,b,c,d,e,f,g,h,i)
+#define STORE(a,b,c,d,e,f,g,h,i,j)
 #define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
 #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));
@@ -500,14 +505,16 @@
 	"               application. The possible values are:\n"
 	"               SUCCESS | USEREXIT | FAILED\n\n"
 	"  Options:\n"
-	"    b      - Play the 'busy' greeting to the calling party.\n"
+	"    b    - Play the 'busy' greeting to the calling party.\n"
 	"    d([c]) - Accept digits for a new extension in context c, if played during\n"
 	"             the greeting.  Context defaults to the current context.\n"
-	"    g(#)   - Use the specified amount of gain when recording the voicemail\n"
-	"             message. The units are whole-number decibels (dB).\n"
-	"    s      - Skip the playback of instructions for leaving a message to the\n"
-	"             calling party.\n"
-	"    u      - Play the 'unavailable' greeting.\n";
+	"    g(#) - Use the specified amount of gain when recording the voicemail\n"
+	"           message. The units are whole-number decibels (dB).\n"
+	"    s    - Skip the playback of instructions for leaving a message to the\n"
+	"           calling party.\n"
+	"    u    - Play the 'unavailable' greeting.\n"
+	"    U    - Mark message as URGENT.\n"
+	"    P    - Mark message as PRIORITY.\n";
 
 static char *synopsis_vmain = "Check Voicemail messages";
 
@@ -606,6 +613,7 @@
  */
 struct mwi_sub {
 	AST_RWLIST_ENTRY(mwi_sub) entry;
+	int old_urgent;
 	int old_new;
 	int old_old;
 	uint32_t uniqueid;
@@ -654,18 +662,21 @@
 static char emaildateformat[32] = "%A, %B %d, %Y at %r";
 
 /* Forward declarations - generic */
-static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box);
+static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box, int urgent);
 static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg, int option, signed char record_gain);
 static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context);
 static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime,
 			char *fmt, int outsidecaller, struct ast_vm_user *vmu, int *duration, const char *unlockdir,
-			signed char record_gain, struct vm_state *vms);
+			signed char record_gain, struct vm_state *vms, char *flag);
 static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain);
 static int vm_play_folder_name(struct ast_channel *chan, char *mbox);
-static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname);
-static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, int imap);
+static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname, char *flag);
+static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, int imap, char *flag);
 static void apply_options(struct ast_vm_user *vmu, const char *options);
 static int is_valid_dtmf(const char *key);
+#if !(defined(IMAP_STORAGE))
+static int check_if_urgent(char *dir, char *filename);
+#endif
 
 #if !(defined(ODBC_STORAGE) || defined(IMAP_STORAGE))
 static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit);
@@ -1586,11 +1597,12 @@
 
 #else
 #ifndef IMAP_STORAGE
-static int count_messages(struct ast_vm_user *vmu, char *dir)
-{
-	/* Find all .txt files - even if they are not in sequence from 0000 */
-
-	int vmcount = 0;
+/* For now, only count URGENT messages in INBOX */
+static int count_messages(struct ast_vm_user *vmu, char *dir, int urgent)
+{
+	/* Find all .txt files - even if they are not in sequence from, int urgent 0000 */
+
+	int vmcount = 0, is_urgent;
 	DIR *vmdir = NULL;
 	struct dirent *vment = NULL;
 
@@ -1599,8 +1611,16 @@
 
 	if ((vmdir = opendir(dir))) {
 		while ((vment = readdir(vmdir))) {
-			if (strlen(vment->d_name) > 7 && !strncmp(vment->d_name + 7, ".txt", 4)) 
-				vmcount++;
+			if (strlen(vment->d_name) > 7 && !strncmp(vment->d_name + 7, ".txt", 4)) {
+				if (urgent == -1) { /* Count all messages */
+					vmcount++;
+				} else {
+					is_urgent = check_if_urgent(dir, vment->d_name);
+					if (is_urgent == urgent) {	/* count urgent or non-urgent as specified */
+						vmcount++;
+					}
+				}
+			}
 		}
 		closedir(vmdir);
 	}
@@ -1873,7 +1893,7 @@
 	return 1;
 }
 
-static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *dur, char *date, char *passdata, size_t passdatasize, const char *category)
+static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *dur, char *date, char *passdata, size_t passdatasize, const char *category, char *flag)
 {
 	char callerid[256];
 	/* Prepare variables for substitution in email body and subject */
@@ -1888,6 +1908,7 @@
 	pbx_builtin_setvar_helper(ast, "VM_CIDNUM", (cidnum ? cidnum : "an unknown caller"));
 	pbx_builtin_setvar_helper(ast, "VM_DATE", date);
 	pbx_builtin_setvar_helper(ast, "VM_CATEGORY", category ? ast_strdupa(category) : "no category");
+	pbx_builtin_setvar_helper(ast, "VM_FLAG", flag);
 }
 
 static char *quote(const char *from, char *to, size_t len)
@@ -1946,7 +1967,7 @@
 	return p;
 }
 
-static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, int imap)
+static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, int imap, char *flag)
 {
 	char date[256];
 	char host[MAXHOSTNAMELEN] = "";
@@ -1991,7 +2012,7 @@
 			int vmlen = strlen(fromstring)*3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, fromstring, passdata, vmlen);
 			len_passdata = strlen(passdata) * 2 + 3;
 			passdata2 = alloca(len_passdata);
@@ -2011,7 +2032,7 @@
 			int vmlen = strlen(emailsubject) * 3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, emailsubject, passdata, vmlen);
 			fprintf(p, "Subject: %s" ENDL, passdata);
 			ast_channel_free(ast);
@@ -2021,9 +2042,9 @@
 		fprintf(p, emailtitle, msgnum + 1, mailbox) ;
 		fprintf(p, ENDL) ;
 	} else if (ast_test_flag((&globalflags), VM_PBXSKIP))
-		fprintf(p, "Subject: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox);
+		fprintf(p, "Subject: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
 	else
-		fprintf(p, "Subject: [PBX]: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox);
+		fprintf(p, "Subject: [PBX]: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
 	fprintf(p, "Message-ID: <Asterisk-%d-%d-%s-%d@%s>" ENDL, msgnum + 1, (unsigned int)ast_random(), mailbox, (int)getpid(), host);
 	if (imap) {
 		/* additional information needed for IMAP searching */
@@ -2032,6 +2053,8 @@
 		fprintf(p, "X-Asterisk-VM-Server-Name: %s" ENDL, fromstring);
 		fprintf(p, "X-Asterisk-VM-Context: %s" ENDL, context);
 		fprintf(p, "X-Asterisk-VM-Extension: %s" ENDL, mailbox);
+                /* flag added for URGENT */
+		fprintf(p, "X-Asterisk-VM-Flag: %s" ENDL, flag);
 		fprintf(p, "X-Asterisk-VM-Priority: %d" ENDL, chan->priority);
 		fprintf(p, "X-Asterisk-VM-Caller-channel: %s" ENDL, chan->name);
 		fprintf(p, "X-Asterisk-VM-Caller-ID-Num: %s" ENDL, cidnum);
@@ -2064,18 +2087,18 @@
 			int vmlen = strlen(emailbody)*3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, emailbody, passdata, vmlen);
 			fprintf(p, "%s" ENDL, passdata);
 			ast_channel_free(ast);
 		} else
 			ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 	} else if (msgnum > -1){
-		fprintf(p, "Dear %s:" ENDL ENDL "\tJust wanted to let you know you were just left a %s long message (number %d)" ENDL
+		fprintf(p, "Dear %s:" ENDL ENDL "\tJust wanted to let you know you were just left a %s long %s message (number %d)" ENDL
 
 		"in mailbox %s from %s, on %s so you might" ENDL
 		"want to check it when you get a chance.  Thanks!" ENDL ENDL "\t\t\t\t--Asterisk" ENDL ENDL, vmu->fullname, 
-		dur, msgnum + 1, mailbox, (cidname ? cidname : (cidnum ? cidnum : "an unknown caller")), date);
+		dur, flag, msgnum + 1, mailbox, (cidname ? cidname : (cidnum ? cidnum : "an unknown caller")), date);
 	} else {
 		fprintf(p, "This message is to let you know that your greeting was changed on %s." ENDL
 				"Please do not delete this message, lest your greeting vanish with it." ENDL ENDL, date);
@@ -2122,7 +2145,7 @@
 #undef ENDL
 }
 
-static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category)
+static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, char *flag)
 {
 	FILE *p=NULL;
 	char tmp[80] = "/tmp/astmail-XXXXXX";
@@ -2141,7 +2164,7 @@
 		ast_log(LOG_WARNING, "Unable to launch '%s' (can't create temporary file)\n", mailcmd);
 		return -1;
 	} else {
-		make_email_file(p, srcemail, vmu, msgnum, context, mailbox, cidnum, cidname, attach, format, duration, attach_user_voicemail, chan, category, 0);
+		make_email_file(p, srcemail, vmu, msgnum, context, mailbox, cidnum, cidname, attach, format, duration, attach_user_voicemail, chan, category, 0, flag);
 		fclose(p);
 		snprintf(tmp2, sizeof(tmp2), "( %s < %s ; rm -f %s ) &", mailcmd, tmp, tmp);
 		ast_safe_system(tmp2);
@@ -2150,7 +2173,7 @@
 	return 0;
 }
 
-static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu, const char *category)
+static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu, const char *category, char *flag)
 {
 	char date[256];
 	char host[MAXHOSTNAMELEN] = "";
@@ -2181,7 +2204,7 @@
 			int vmlen = strlen(fromstring)*3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, pagerfromstring, passdata, vmlen);
 			fprintf(p, "From: %s <%s>\n", passdata, who);
 			ast_channel_free(ast);
@@ -2197,14 +2220,14 @@
 			int vmlen = strlen(pagersubject) * 3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, pagersubject, passdata, vmlen);
 			fprintf(p, "Subject: %s\n\n", passdata);
 			ast_channel_free(ast);
 		} else
 			ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 	} else
-		fprintf(p, "Subject: New VM\n\n");
+		fprintf(p, "Subject: New %s VM\n\n", flag);
 
 	ast_strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
 	if (pagerbody) {
@@ -2214,15 +2237,15 @@
 			int vmlen = strlen(pagerbody) * 3 + 200;
 			passdata = alloca(vmlen);
 			memset(passdata, 0, vmlen);
-			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+			prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
 			pbx_substitute_variables_helper(ast, pagerbody, passdata, vmlen);
 			fprintf(p, "%s\n", passdata);
 			ast_channel_free(ast);
 		} else
 			ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
 	} else {
-		fprintf(p, "New %s long msg in box %s\n"
-				"from %s, on %s", dur, mailbox, (cidname ? cidname : (cidnum ? cidnum : "unknown")), date);
+		fprintf(p, "New %s long %s msg in box %s\n"
+				"from %s, on %s", dur, flag, mailbox, (cidname ? cidname : (cidnum ? cidnum : "unknown")), date);
 	}
 	fclose(p);
 	snprintf(tmp2, sizeof(tmp2), "( %s < %s ; rm -f %s ) &", mailcmd, tmp, tmp);
@@ -2348,7 +2371,7 @@
 
 #ifdef ODBC_STORAGE
 /*! XXX \todo Fix this function to support multiple mailboxes in the intput string */
-static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	int x = -1;
 	int res;
@@ -2364,6 +2387,8 @@
 		*newmsgs = 0;
 	if (oldmsgs)
 		*oldmsgs = 0;
+	if (urgentmsgs)
+		*urgentmsgs = 0;
 
 	/* If no mailbox, return immediately */
 	if (ast_strlen_zero(mailbox))
@@ -2498,7 +2523,7 @@
 
 #elif defined(IMAP_STORAGE)
 
-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 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, char *flag)
 {
 	char *myserveremail = serveremail;
 	char fn[PATH_MAX];
@@ -2510,6 +2535,14 @@
 	void *buf;
 	int tempcopy = 0;
 	STRING str;
+	int ret; /* for better error checking */
+	char *imapflags = NIL;
+
+	/* Set urgent flag for IMAP message */
+	if (flag != NULL && !strcmp(flag,"URGENT")) {
+		ast_debug(3, "Setting message flag \\\\FLAGGED.\n");
+		imapflags="\\FLAGGED";
+	}
 	
 	/* Attach only the first format */
 	fmt = ast_strdupa(fmt);
@@ -2551,7 +2584,7 @@
 		imap_delete_old_greeting(fn, vms);
 	}
 	
-	make_email_file(p, myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), fn, fmt, duration, 1, chan, NULL, 1);
+	make_email_file(p, myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), fn, fmt, duration, 1, chan, NULL, 1, flag);
 	/* read mail file to memory */		
 	len = ftell(p);
 	rewind(p);
@@ -2565,13 +2598,21 @@
 	fread(buf, len, 1, p);
 	((char *)buf)[len] = '\0';
 	INIT(&str, mail_string, buf, len);
-	init_mailstream(vms, NEW_FOLDER);
-	imap_mailbox_name(mailbox, sizeof(mailbox), vms, NEW_FOLDER, 1);
-	if (!mail_append(vms->mailstream, mailbox, &str))
-		ast_log(LOG_ERROR, "Error while sending the message to %s\n", mailbox);
-	fclose(p);
-	unlink(tmp);
-	ast_free(buf);
+	ret = init_mailstream(vms, NEW_FOLDER);
+	if (ret == 0) {
+		imap_mailbox_name(mailbox, sizeof(mailbox), vms, NEW_FOLDER, 1);
+		if(!mail_append_full(vms->mailstream, mailbox, imapflags, NIL, &str))
+			ast_log(LOG_ERROR, "Error while sending the message to %s\n", mailbox);
+		fclose(p);
+		unlink(tmp);
+		ast_free(buf);
+	} else {
+		ast_log(LOG_ERROR, "Could not initialize mailstream for %s\n",mailbox);
+		fclose(p);
+		unlink(tmp);
+		ast_free(buf);
+		return -1;
+	}
 	ast_debug(3, "%s stored\n", fn);
 	
 	if (tempcopy)
@@ -2628,6 +2669,9 @@
 		if (fold == 1) {/*Old messages*/
 		 	return vms_p->oldmessages;
 		}
+		if(fold == 2) {/*URGENT messages*/
+		 	return vms_p->urgentmessages;
+		}
 	}
 
 	/* add one if not there... */
@@ -2671,6 +2715,11 @@
 			pgm->unseen = 0;
 			pgm->seen = 1;
 		}
+		/* look for urgent messages */
+		if (fold == 2) {
+                	pgm->flagged = 1;
+                	pgm->unflagged = 0;
+		}
 		pgm->undeleted = 1;
 		pgm->deleted = 0;
 
@@ -2680,6 +2729,8 @@
 			vms_p->newmessages = vms_p->vmArrayIndex;
 		if (fold == 1)
 			vms_p->oldmessages = vms_p->vmArrayIndex;
+		if(fold == 2)
+			vms_p->urgentmessages = vms_p->vmArrayIndex;
 		/*Freeing the searchpgm also frees the searchhdr*/
 		mail_free_searchpgm(&pgm);
 		vms_p->updated = 0;
@@ -2689,7 +2740,7 @@
 	}
 	return 0;
 }
-static int inboxcount(const char *mailbox_context, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox_context, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	char tmp[PATH_MAX] = "";
 	char *mailboxnc; 	
@@ -2700,6 +2751,8 @@
 		*newmsgs = 0;
 	if (oldmsgs)
 		*oldmsgs = 0;
+	if (urgentmsgs)
+		*urgentmsgs = 0;
 
 	ast_debug(3,"Mailbox is set to %s\n",mailbox_context);
 	/* If no mailbox, return immediately */
@@ -2709,18 +2762,20 @@
 	ast_copy_string(tmp, mailbox_context, sizeof(tmp));
 	context = strchr(tmp, '@');
 	if (strchr(mailbox_context, ',')) {
-		int tmpnew, tmpold;
+		int tmpnew, tmpold, tmpurgent;
 		ast_copy_string(tmp, mailbox_context, sizeof(tmp));
 		mb = tmp;
 		while ((cur = strsep(&mb, ", "))) {
 			if (!ast_strlen_zero(cur)) {
-				if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+				if (inboxcount(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
 					return -1;
 				else {
 					if (newmsgs)
 						*newmsgs += tmpnew; 
 					if (oldmsgs)
 						*oldmsgs += tmpold;
+					if (urgentmsgs)
+						*urgentmsgs += tmpurgent;
 				}
 			}
 		}
@@ -2740,6 +2795,10 @@
 	}
 	if (oldmsgs) {
 		if ((*oldmsgs = messagecount(context, mailboxnc, "Old")) < 0)
+			return -1;
+	}
+	if (urgentmsgs) {
+		if((*urgentmsgs = messagecount(context, mailboxnc, "URGENT")) < 0)
 			return -1;
 	}
 	return 0;
@@ -2766,7 +2825,7 @@
 	return messagecount(context, tmp, folder) ? 1 : 0;
 }
 
-static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir)
+static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, char *flag)
 {
 	struct vm_state *sendvms = NULL, *destvms = NULL;
 	char messagestring[10]; /*I guess this could be a problem if someone has more than 999999999 messages...*/
@@ -2788,7 +2847,7 @@
 #endif
 #ifndef IMAP_STORAGE
 /* copy message only used by file storage */
-static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir)
+static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir, char *flag)
 {
 	char fromdir[PATH_MAX], todir[PATH_MAX], frompath[PATH_MAX], topath[PATH_MAX];
 	const char *frombox = mbox(imbox);
@@ -2817,7 +2876,7 @@
 		ast_log(LOG_ERROR, "Recipient mailbox %s@%s is full\n", recip->mailbox, recip->context);
 	}
 	ast_unlock_path(todir);
-	notify_new_message(chan, recip, recipmsgnum, duration, fmt, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL));
+	notify_new_message(chan, recip, recipmsgnum, duration, fmt, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), flag);
 	
 	return 0;
 }
@@ -2828,6 +2887,46 @@
 	return __has_voicemail(context, mailbox, folder, 0);
 }
 
+static int check_if_urgent(char *dir, char *filename)
+{
+	unsigned char buf[256]; 
+	char flag[80]="";
+	char *val;
+	FILE *f;
+	char path[256]; 
+
+	snprintf(path, sizeof(path), "%s/%s", dir, filename);
+	ast_debug(1, "About to open file %s\n", path);
+	f = fopen(path, "r");
+
+	if (f) {
+		while (!feof(f)) {	
+			fgets((char *)buf, sizeof(buf), f);
+			if (!feof(f)) {
+				/* ast_debug(1, "parsing line %s in file %s\n", buf, filename); */
+				char *stringp=NULL;
+				stringp = (char *)buf;
+				strsep(&stringp, "=");
+				val = strsep(&stringp, "=");
+				if (!ast_strlen_zero(val)) {
+					ast_debug(1, "** buf is set to %s\n", buf);
+					if (strncmp((char *)buf, "flag", 4) == 0) {
+						ast_copy_string(flag, val, sizeof(flag));
+						ast_debug(1, "Found flag %s in file %s\n", flag, filename);
+						if (flag && strncmp(flag,"URGENT",6) == 0) {
+							ast_debug(1, "Found URGENT flag %s in file %s\n", flag, filename);
+							return 1;
+						}
+					}
+				}
+			}
+		}
+		fclose(f);
+	} else {
+		ast_log(LOG_WARNING, "Could not open file %s\n", path);
+	}
+	return 0;
+}
 
 static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit)
 {
@@ -2835,6 +2934,7 @@
 	struct dirent *de;
 	char fn[256];
 	int ret = 0;
+	int urgent = 0, is_urgent = 0;
 
 	/* If no mailbox, return immediately */
 	if (ast_strlen_zero(mailbox))
@@ -2844,6 +2944,12 @@
 		folder = "INBOX";
 	if (ast_strlen_zero(context))
 		context = "default";
+
+	/* check if we are looking for URGENT messages */
+	if (strcmp(folder,"URGENT") == 0) {
+		folder = "INBOX";
+		urgent = 1;
+	}
 
 	snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, mailbox, folder);
 
@@ -2855,8 +2961,12 @@
 			if (shortcircuit) {
 				ret = 1;
 				break;
-			} else if (!strncasecmp(de->d_name + 8, "txt", 3))
-				ret++;
+			} else if (!strncasecmp(de->d_name + 8, "txt", 3)) {
+				is_urgent = check_if_urgent(fn, de->d_name);
+				if (is_urgent == urgent) {	/* count urgent or non-urgent as specified */
+					ret++;
+				}
+			}
 		}
 	}
 
@@ -2864,7 +2974,6 @@
 
 	return ret;
 }
-
 
 static int has_voicemail(const char *mailbox, const char *folder)
 {
@@ -2882,7 +2991,7 @@
 }
 
 
-static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	char tmp[256];
 	char *context;
@@ -2895,22 +3004,26 @@
 		*newmsgs = 0;
 	if (oldmsgs)
 		*oldmsgs = 0;
+	if (urgentmsgs)
+		*urgentmsgs = 0;
 
 	if (strchr(mailbox, ',')) {
-		int tmpnew, tmpold;
+		int tmpnew, tmpold, tmpurgent;
 		char *mb, *cur;
 
 		ast_copy_string(tmp, mailbox, sizeof(tmp));
 		mb = tmp;
 		while ((cur = strsep(&mb, ", "))) {
 			if (!ast_strlen_zero(cur)) {
-				if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+				if (inboxcount(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
 					return -1;
 				else {
 					if (newmsgs)
 						*newmsgs += tmpnew; 
 					if (oldmsgs)
 						*oldmsgs += tmpold;
+					if (urgentmsgs)
+						*urgentmsgs += tmpurgent;
 				}
 			}
 		}
@@ -2928,17 +3041,19 @@
 		*newmsgs = __has_voicemail(context, tmp, "INBOX", 0);
 	if (oldmsgs)
 		*oldmsgs = __has_voicemail(context, tmp, "Old", 0);
+	if (urgentmsgs)
+		*urgentmsgs = __has_voicemail(context, tmp, "URGENT", 0);
 
 	return 0;
 }
 
 #endif
 
-static void run_externnotify(char *context, char *extension)
+static void run_externnotify(char *context, char *extension, char *flag)
 {
 	char arguments[255];
 	char ext_context[256] = "";
-	int newvoicemails = 0, oldvoicemails = 0;
+	int newvoicemails = 0, oldvoicemails = 0, urgentvoicemails = 0;
 	struct ast_smdi_mwi_message *mwi_msg;
 
 	if (!ast_strlen_zero(context))
@@ -2966,10 +3081,10 @@
 	}
 
 	if (!ast_strlen_zero(externnotify)) {
-		if (inboxcount(ext_context, &newvoicemails, &oldvoicemails)) {
+		if (inboxcount(ext_context, &urgentvoicemails, &newvoicemails, &oldvoicemails)) {
 			ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
 		} else {
-			snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails);
+			snprintf(arguments, sizeof(arguments), "%s %s %s %d %s&", externnotify, context, extension, newvoicemails, flag ? flag : "");
 			ast_debug(1, "Executing %s\n", arguments);
 			ast_safe_system(arguments);
 		}
@@ -2985,7 +3100,7 @@
 static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_options *options)
 {
 #ifdef IMAP_STORAGE
-	int newmsgs, oldmsgs;
+	int newmsgs, oldmsgs, urgentmsgs;
 	struct vm_state *vms = NULL;
 #endif
 	char txtfile[PATH_MAX], tmptxtfile[PATH_MAX];
@@ -3016,6 +3131,7 @@
 	struct ast_vm_user *vmu;
 	struct ast_vm_user svm;
 	const char *category = NULL, *code, *alldtmf = "0123456789ABCD*#";
+	char flag[80];
 
 	ast_copy_string(tmp, ext, sizeof(tmp));
 	ext = tmp;
@@ -3030,6 +3146,14 @@
 		*tmpptr++ = '\0';
 
 	category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
+
+	if (ast_test_flag(options, OPT_MESSAGE_URGENT)) {
+		ast_copy_string(flag, "URGENT", sizeof(flag));
+	} else if (ast_test_flag(options, OPT_MESSAGE_PRIORITY)) {
+		ast_copy_string(flag, "PRIORITY", sizeof(flag));
+	} else {
+		flag[0] = '\0';
+	}
 
 	ast_debug(3, "Before find_user\n");
 	if (!(vmu = find_user(&svm, context, ext))) {
@@ -3194,7 +3318,7 @@
 #ifdef IMAP_STORAGE
 		/* Is ext a mailbox? */
 		/* must open stream for this user to get info! */
-		res = inboxcount(ext_context, &newmsgs, &oldmsgs);
+		res = inboxcount(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
 		if (res < 0) {
 			ast_log(LOG_NOTICE,"Can not leave voicemail, unable to count messages\n");
 			return -1;
@@ -3241,7 +3365,7 @@
 		}
 
 #else
-		if (count_messages(vmu, dir) >= vmu->maxmsg) {
+		if (count_messages(vmu, dir, -1) >= vmu->maxmsg) {
 			res = ast_streamfile(chan, "vm-mailboxfull", chan->language);
 			if (!res)
 				res = ast_waitstream(chan, "");
@@ -3304,16 +3428,17 @@
 				chan->name,
 				ast_callerid_merge(callerid, sizeof(callerid), S_OR(chan->cid.cid_name, NULL), S_OR(chan->cid.cid_num, NULL), "Unknown"),
 				date, (long)time(NULL),
-				category ? category : ""); 
+				category ? category : "");
 		} else
 			ast_log(LOG_WARNING, "Error opening text file for output\n");
 #ifdef IMAP_STORAGE
-		res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, NULL, options->record_gain, vms);
+		res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, NULL, options->record_gain, vms, flag);
 #else
-		res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, NULL, options->record_gain, NULL);
+		res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, NULL, options->record_gain, NULL, flag);
 #endif
 
 		if (txt) {
+			fprintf(txt, "flag=%s\n", flag);
 			if (duration < vmminsecs) {
 				fclose(txt);
 				if (option_verbose > 2) 
@@ -3372,7 +3497,7 @@
 					 * ODBC storage does the entire copy with SQL.
 					 */
 					if (ast_fileexists(fn, NULL, NULL) > 0) {
-						STORE(dir, vmu->mailbox, vmu->context, msgnum, chan, vmu, fmt, duration, vms);
+						STORE(dir, vmu->mailbox, vmu->context, msgnum, chan, vmu, fmt, duration, vms, flag);
 					}
 
 					/* Are there to be more recipients of this message? */
@@ -3387,13 +3512,13 @@
 							context++;
 						}
 						if ((recip = find_user(&recipu, context, exten))) {
-							copy_message(chan, vmu, 0, msgnum, duration, recip, fmt, dir);
+							copy_message(chan, vmu, 0, msgnum, duration, recip, fmt, dir, flag);
 							free_user(recip);
 						}
 					}
 					/* Notification and disposal needs to happen after the copy, though. */
 					if (ast_fileexists(fn, NULL, NULL)) {
-						notify_new_message(chan, vmu, msgnum, duration, fmt, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL));
+						notify_new_message(chan, vmu, msgnum, duration, fmt, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), flag);
 						DISPOSE(dir, msgnum);
 					}
 				}
@@ -4098,7 +4223,8 @@
 				snprintf(duration_str, 11, "%ld", *duration);
 				if (!ast_variable_update(msg_cat, "duration", duration_str, NULL, 0)) {
 					config_text_file_save(textfile, msg_cfg, "app_voicemail");
-					STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, *duration, vms);
+					/* flags not set, so not sent here */
+					STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, *duration, vms, NULL);
 				}
 			}
 
@@ -4131,7 +4257,7 @@
 	return cmd;
 }
 
-static void queue_mwi_event(const char *mbox, int new, int old)
+static void queue_mwi_event(const char *mbox, int urgent, int new, int old)
 {
 	struct ast_event *event;
 	char *mailbox, *context;
@@ -4145,7 +4271,7 @@
 	if (!(event = ast_event_new(AST_EVENT_MWI,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
 			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, new,
+			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, (new+urgent),
 			AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old,
 			AST_EVENT_IE_END))) {
 		return;
@@ -4157,10 +4283,10 @@
 		AST_EVENT_IE_END);
 }
 
-static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname)
+static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname, char *flag)
 {
 	char todir[PATH_MAX], fn[PATH_MAX], ext_context[PATH_MAX], *stringp;
-	int newmsgs = 0, oldmsgs = 0;
+	int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;
 	const char *category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
 	char *myserveremail = serveremail;
 
@@ -4192,14 +4318,14 @@
 			RETRIEVE(todir, msgnum, vmu->mailbox, vmu->context);
 
 		/*XXX possible imap issue, should category be NULL XXX*/
-		sendmail(myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, fn, fmt, duration, attach_user_voicemail, chan, category);
+		sendmail(myserveremail, vmu, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, fn, fmt, duration, attach_user_voicemail, chan, category, flag);
 
 		if (attach_user_voicemail)
 			DISPOSE(todir, msgnum);
 	}
 
 	if (!ast_strlen_zero(vmu->pager))
-		sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu, category);
+		sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu, category, flag);
 
 	if (ast_test_flag(vmu, VM_DELETE))
 		DELETE(todir, msgnum, fn);
@@ -4209,16 +4335,16 @@
 #endif
 	/* Leave voicemail for someone */
 	if (ast_app_has_voicemail(ext_context, NULL)) 
-		ast_app_inboxcount(ext_context, &newmsgs, &oldmsgs);
-
-	queue_mwi_event(ext_context, newmsgs, oldmsgs);
+		ast_app_inboxcount(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
+
+	queue_mwi_event(ext_context, urgentmsgs, newmsgs, oldmsgs);
 
 	manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s@%s\r\nWaiting: %d\r\nNew: %d\r\nOld: %d\r\n", vmu->mailbox, vmu->context, ast_app_has_voicemail(ext_context, NULL), newmsgs, oldmsgs);
-	run_externnotify(vmu->context, vmu->mailbox);
+	run_externnotify(vmu->context, vmu->mailbox, flag);
 	return 0;
 }
 
-static int forward_message(struct ast_channel *chan, char *context, struct vm_state *vms, struct ast_vm_user *sender, char *fmt, int flag, signed char record_gain)
+static int forward_message(struct ast_channel *chan, char *context, struct vm_state *vms, struct ast_vm_user *sender, char *fmt, int flag, signed char record_gain, char *flag2)
 {
 #ifdef IMAP_STORAGE
 	BODY *body;
@@ -4442,8 +4568,8 @@
 					if (!dstvms->mailstream) {
 						ast_log (LOG_ERROR,"IMAP mailstream for %s is NULL\n",vmtmp->mailbox);
 					} else {
-						STORE(todir, vmtmp->mailbox, vmtmp->context, dstvms->curmsg, chan, vmtmp, fmt, duration, dstvms);
-						run_externnotify(vmtmp->context, vmtmp->mailbox); 
+						STORE(todir, vmtmp->mailbox, vmtmp->context, dstvms->curmsg, chan, vmtmp, fmt, duration, dstvms, flag2);
+						run_externnotify(vmtmp->context, vmtmp->mailbox, flag2); 
 					}
 				} else {
 					ast_log (LOG_ERROR,"Could not find state information for mailbox %s\n",vmtmp->mailbox);
@@ -4453,10 +4579,10 @@
 					myserveremail = vmtmp->serveremail;
 				attach_user_voicemail = ast_test_flag(vmtmp, VM_ATTACH);
 				/* NULL category for IMAP storage */
-				sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), vms->fn, fmt, duration, attach_user_voicemail, chan, NULL);
+				sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), vms->fn, fmt, duration, attach_user_voicemail, chan, NULL, flag2);
 
 #else
-				copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir);
+				copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir, flag2);
 #endif
 				saved_messages++;
 				AST_LIST_REMOVE_CURRENT(list);
@@ -4710,6 +4836,7 @@
 	char *attachedfilefmt;
 	char *temp;
 	char buf[1024];
+	char flag[10];
 
 	vms->starting = 0; 
 	ast_debug(3,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
@@ -4726,6 +4853,16 @@
 		ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
 		return -1;
 	}
+
+	/* Get URGENT flag from headers */
+	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Flag:", buf, sizeof(buf));
+	ast_debug(3,"Voicemail FLAG set to %s\n",temp);
+
+	if (temp)
+		ast_copy_string(flag, temp, sizeof(flag));
+	else
+		flag[0] = '\0';
+
 	snprintf(todir, sizeof(todir), "%s%s/%s/tmp", VM_SPOOL_DIR, vmu->context, vmu->mailbox);

[... 1039 lines stripped ...]



More information about the asterisk-commits mailing list