[asterisk-commits] mogorman: branch mogorman/asterisk-5162 r41766 - in /team/mogorman/asterisk-5...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Sep 1 15:11:48 MST 2006


Author: mogorman
Date: Fri Sep  1 17:11:48 2006
New Revision: 41766

URL: http://svn.digium.com/view/asterisk?rev=41766&view=rev
Log:
updates

Modified:
    team/mogorman/asterisk-5162/   (props changed)
    team/mogorman/asterisk-5162/apps/app_voicemail.c
    team/mogorman/asterisk-5162/channels/chan_sip.c
    team/mogorman/asterisk-5162/main/channel.c
    team/mogorman/asterisk-5162/main/file.c
    team/mogorman/asterisk-5162/main/pbx.c
    team/mogorman/asterisk-5162/main/rtp.c

Propchange: team/mogorman/asterisk-5162/
------------------------------------------------------------------------------
Binary property 'branch-1.2-blocked' - no diff available.

Propchange: team/mogorman/asterisk-5162/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.

Propchange: team/mogorman/asterisk-5162/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Sep  1 17:11:48 2006
@@ -1,1 +1,1 @@
-/trunk:1-41667
+/trunk:1-41765

Modified: team/mogorman/asterisk-5162/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-5162/apps/app_voicemail.c?rev=41766&r1=41765&r2=41766&view=diff
==============================================================================
--- team/mogorman/asterisk-5162/apps/app_voicemail.c (original)
+++ team/mogorman/asterisk-5162/apps/app_voicemail.c Fri Sep  1 17:11:48 2006
@@ -89,10 +89,10 @@
 #endif
 
 #ifdef IMAP_STORAGE
-char *curhst = NIL;           /* currently connected host */
-char *curusr = NIL;           /* current login user */
-
-char temp[1024];
+static char *curhst = NIL;	/* currently connected host */
+static char *curusr = NIL;	/* current login user */
+
+static char temp[1024];
 
 static char imapserver[48];
 static char imapport[8];
@@ -104,10 +104,10 @@
 
 struct vm_state;
 
-int init_mailstream (struct vm_state *vms);
-void write_file (char *filename, char *buffer, unsigned long len);
-void status (MAILSTREAM *stream);
-void display_body (BODY *body, char *pfx, long i);
+static int init_mailstream (struct vm_state *vms);
+static void write_file (char *filename, char *buffer, unsigned long len);
+static void status (MAILSTREAM *stream);
+static void display_body (BODY *body, char *pfx, long i);
 static char *get_header_by_tag(char *header, char *tag);
 static void vm_imap_delete(int msgnum, struct vm_state *vms);
 static char *get_user_by_mailbox(char *mailbox);
@@ -122,12 +122,12 @@
 static int save_body(BODY *body, struct vm_state *vms, char *section, char *format);
 static int make_gsm_file(char *dest, char *imapuser, char *dir, int num);
 static void get_mailbox_delimiter(MAILSTREAM *stream);
-void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota);
+static void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota);
 /* should define TMP in config file... */
 #define TMP "/tmp"
 struct vmstate {
-      struct vm_state *vms;
-      struct vmstate *next;
+	struct vm_state *vms;
+	struct vmstate *next;
 };
 AST_MUTEX_DEFINE_STATIC(vmstate_lock);
 static struct vmstate *vmstates = NULL;
@@ -309,7 +309,7 @@
 	int saydurationm;
 	int maxmsg;                      /*!< Maximum number of msgs per folder for this mailbox */
 #ifdef IMAP_STORAGE
-		char imapuser[80];	/* IMAP server login */
+	char imapuser[80];	/* IMAP server login */
 #endif
 	double volgain;		/*!< Volume gain for voicemails sent via email */
 	AST_LIST_ENTRY(ast_vm_user) list;
@@ -908,10 +908,11 @@
 		ast_log(LOG_WARNING, "msgnum %d, mailbox message %lu is zero.\n",msgnum,messageNum);
 		return;
 	}
-	ast_log(LOG_DEBUG, "deleting msgnum %d, which is mailbox message %lu\n",msgnum,messageNum);
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG, "deleting msgnum %d, which is mailbox message %lu\n",msgnum,messageNum);
 	/* delete message */
-        sprintf (arg,"%lu",messageNum);
-        mail_setflag (vms->mailstream,arg,"\\DELETED");
+	sprintf (arg,"%lu",messageNum);
+	mail_setflag (vms->mailstream,arg,"\\DELETED");
 }
 
 #endif
@@ -1990,16 +1991,14 @@
 			base_encode(fname, p);
 #ifdef IMAP_STORAGE
 			/* only attach if necessary */
-			ast_log(LOG_DEBUG, "Before second attachment with format set to:%s\n",format);
 			if (strcmp(format, "gsm")) {
-			   fprintf(p, "--%s\n", bound);
-			   fprintf(p, "Content-Type: audio/x-gsm; name=\"msg%04d.%s\"\n", msgnum, format);
-			   fprintf(p, "Content-Transfer-Encoding: base64\n");
-			   fprintf(p, "Content-Description: Voicemail sound attachment.\n");
-			   fprintf(p, "Content-Disposition: attachment; filename=\"msg%04d.gsm\"\n\n", msgnum);
-
-			   snprintf(fname, sizeof(fname), "%s.gsm", attach);
-			   base_encode(fname, p);
+				fprintf(p, "--%s\n", bound);
+				fprintf(p, "Content-Type: audio/x-gsm; name=\"msg%04d.%s\"\n", msgnum, format);
+				fprintf(p, "Content-Transfer-Encoding: base64\n");
+				fprintf(p, "Content-Description: Voicemail sound attachment.\n");
+				fprintf(p, "Content-Disposition: attachment; filename=\"msg%04d.gsm\"\n\n", msgnum);
+				snprintf(fname, sizeof(fname), "%s.gsm", attach);
+				base_encode(fname, p);
 			}
 #endif
 			fprintf(p, "\n\n--%s--\n.\n", bound);
@@ -2151,13 +2150,13 @@
 	static const char *msgs[] = {
 		"INBOX",
 		"Old",
-		"Work",   
+		"Work",
 		"Family",
 		"Friends",
 		"Cust1",
 		"Cust2",
 		"Cust3",
-		"Cust4",  
+		"Cust4",
 		"Cust5",
 	};
 	return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
@@ -2187,10 +2186,10 @@
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
 	
 	context = strchr(tmp, '@');
-	if (context) {   
+	if (context) {
 		*context = '\0';
 		context++;
-	} else  
+	} else
 		context = "default";
 	
 	obj = odbc_request_obj(odbc_database, 0);
@@ -2302,7 +2301,7 @@
 		}
 		snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder);
 		res = SQLPrepare(stmt, sql, SQL_NTS);
-		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {  
+		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
 			SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 			goto yuck;
@@ -2355,8 +2354,8 @@
 #ifdef IMAP_STORAGE
 static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
-   	SEARCHPGM *pgm;
-   	SEARCHHEADER *hdr;
+	SEARCHPGM *pgm;
+	SEARCHHEADER *hdr;
  
  	struct ast_vm_user *vmu;
  	struct vm_state *vms_p;
@@ -2370,7 +2369,8 @@
  	if (oldmsgs)
  		*oldmsgs = 0;
  
- 	ast_log (LOG_DEBUG,"Mailbox is set to %s\n",mailbox);
+	if(option_debug > 2)
+	 	ast_log (LOG_DEBUG,"Mailbox is set to %s\n",mailbox);
  	/* If no mailbox, return immediately */
  	if (ast_strlen_zero(mailbox))
  		return 0;
@@ -2406,15 +2406,15 @@
  	}
  
  	/* We have to get the user before we can open the stream! */
-   	/*ast_log (LOG_DEBUG,"Before find_user, context is %s and mailbox is %s\n",context,mailbox); */
+ 	/*ast_log (LOG_DEBUG,"Before find_user, context is %s and mailbox is %s\n",context,mailbox); */
  	vmu = find_user(NULL, context, mailboxnc);
  	if (vmu == NULL) {
-   		ast_log (LOG_ERROR,"Couldn't find mailbox %s in context %s\n",mailboxnc,context);
+		ast_log (LOG_ERROR,"Couldn't find mailbox %s in context %s\n",mailboxnc,context);
  		return -1;
  	} else {
  		/* No IMAP account available */
  		if (vmu->imapuser[0] == '\0') {
-   			ast_log (LOG_WARNING,"IMAP user not set for mailbox %s\n",vmu->mailbox);
+			ast_log (LOG_WARNING,"IMAP user not set for mailbox %s\n",vmu->mailbox);
  			return -1;
  		}
  	}
@@ -2425,7 +2425,8 @@
  		vms_p = get_vm_state_by_mailbox(mailboxnc,1);
  	}
  	if (vms_p != NULL) {
-   		ast_log (LOG_DEBUG,"Returning before search - user is logged in\n");
+		if(option_debug > 2)
+			ast_log (LOG_DEBUG,"Returning before search - user is logged in\n");
  		*newmsgs = vms_p->newmessages;
  		*oldmsgs = vms_p->oldmessages;
  		return 0;
@@ -2438,12 +2439,14 @@
  	}
  
  	if (vms_p == NULL) {
-   		ast_log (LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser);
+		if(option_debug > 2)
+			ast_log (LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser);
  		vms_p = (struct vm_state *)malloc(sizeof(struct vm_state));
  		strcpy(vms_p->imapuser,vmu->imapuser);
  		strcpy(vms_p->username,mailboxnc); /* save for access from interactive entry point */
  		vms_p->mailstream = NIL; /* save for access from interactive entry point */
-   		ast_log (LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
+		if(option_debug > 2)
+			ast_log (LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
  		vms_p->updated = 1;
  		vms_p->interactive = 0;
  		/* set mailbox to INBOX! */
@@ -2454,13 +2457,13 @@
  	if (vms_p->mailstream == NULL)
  		ret = init_mailstream(vms_p);
  	if (vms_p->mailstream == NULL) {
-   		ast_log (LOG_ERROR,"Houston we have a problem - IMAP mailstream is NULL\n");
+		ast_log (LOG_ERROR,"Houston we have a problem - IMAP mailstream is NULL\n");
  		return -1;
  	}
  	if (newmsgs && ret==0 && vms_p->updated==1 ) {
-   		pgm = mail_newsearchpgm ();
-   		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
-   		pgm->header = hdr;
+		pgm = mail_newsearchpgm ();
+		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
+		pgm->header = hdr;
  		pgm->unseen = 1;
  		pgm->seen = 0;
  		pgm->undeleted = 1;
@@ -2468,17 +2471,14 @@
  
  		vms_p->vmArrayIndex = 0;
  	
-   		ast_log (LOG_DEBUG,"Before search of mailbox %s for NEW messages\n",vms_p->mailstream->mailbox);
-   		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
-   		ast_log (LOG_DEBUG,"After search\n");
+		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
  		*newmsgs = vms_p->vmArrayIndex;
  		vms_p->newmessages = vms_p->vmArrayIndex;
-   		ast_log (LOG_DEBUG,"There are %d NEW messages\n",vms_p->newmessages);
  	}
  	if (oldmsgs && ret==0 && vms_p->updated==1 ) {
-   		pgm = mail_newsearchpgm ();
-   		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
-   		pgm->header = hdr;
+		pgm = mail_newsearchpgm ();
+		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
+		pgm->header = hdr;
  		pgm->unseen = 0;
  		pgm->seen = 1;
  		pgm->deleted = 0;
@@ -2486,18 +2486,15 @@
  
  		vms_p->vmArrayIndex = 0;
  	
-   		ast_log (LOG_DEBUG,"Before search of mailbox %s for OLD messages\n",vms_p->mailstream->mailbox);
-   		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
+		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
  		*oldmsgs = vms_p->vmArrayIndex;
  		vms_p->oldmessages = vms_p->vmArrayIndex;
-   		ast_log (LOG_DEBUG,"There are %d OLD messages\n",vms_p->oldmessages);
  	}
  	if (vms_p->updated == 1) {  /* changes, so we did the searches above */
  		vms_p->updated = 0;
  	} else if (vms_p->updated > 1) {  /* decrement delay count */
  		vms_p->updated--;
  	} else {  /* no changes, so don't search */
-   		ast_log (LOG_DEBUG,"Calling mail_ping on mailbox %s\n",vms_p->mailstream->mailbox);
  		mail_ping(vms_p->mailstream);
  		/* Keep the old data */
  		*newmsgs = vms_p->newmessages;
@@ -2518,7 +2515,7 @@
 	ast_log(LOG_NOTICE, "Copying message from %s@%s to %s@%s\n", vmu->mailbox, vmu->context, recip->mailbox, recip->context);
 
 	create_dirpath(todir, sizeof(todir), recip->context, recip->mailbox, "INBOX");
-  
+
 	make_dir(fromdir, sizeof(fromdir), vmu->context, vmu->mailbox, frombox);
 	make_file(frompath, sizeof(frompath), fromdir, msgnum);
 
@@ -2701,7 +2698,7 @@
 	char callerid[256];
 	FILE *txt;
 	char date[256];
-	int  txtdes;
+	int txtdes;
 #endif
 	int res = 0;
 	int msgnum;
@@ -2737,7 +2734,8 @@
 
 	category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
 
-	ast_log(LOG_DEBUG, "Before find_user\n");
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG, "Before find_user\n");
 	if (!(vmu = find_user(&svm, context, ext))) {
 		ast_log(LOG_WARNING, "No entry in voicemail config file for '%s'\n", ext);
 		if (ast_test_flag(options, OPT_PRIORITY_JUMP) || ast_opt_priority_jumping)
@@ -2783,11 +2781,11 @@
 
 	if (!ast_strlen_zero(vmu->exit)) {
 		if (ast_exists_extension(chan, vmu->exit, "a", 1, chan->cid.cid_num))
-			strncat(ecodes, "*", sizeof(ecodes) -  strlen(ecodes) - 1);
+			strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
 	} else if (ast_exists_extension(chan, chan->context, "a", 1, chan->cid.cid_num))
-		strncat(ecodes, "*", sizeof(ecodes) -  strlen(ecodes) - 1);
+		strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
 	else if (!ast_strlen_zero(chan->macrocontext) && ast_exists_extension(chan, chan->macrocontext, "a", 1, chan->cid.cid_num)) {
-		strncat(ecodes, "*", sizeof(ecodes) -  strlen(ecodes) - 1);
+		strncat(ecodes, "*", sizeof(ecodes) - strlen(ecodes) - 1);
 		ausemacro = 1;
 	}
 
@@ -2824,7 +2822,7 @@
 	if (res > 0)
 		ast_stopstream(chan);
 	/* Check for a '*' here in case the caller wants to escape from voicemail to something
-	   other than the operator -- an automated attendant or mailbox login for example */
+	 other than the operator -- an automated attendant or mailbox login for example */
 	if (res == '*') {
 		chan->exten[0] = 'a';
 		chan->exten[1] = '\0';
@@ -2872,11 +2870,11 @@
 		/* must open stream for this user to get info! */
 		vms = get_vm_state_by_mailbox(ext,0);
 		if (vms != NULL) {
-			ast_log(LOG_DEBUG, "Using vm_state, interactive set to %d.\n",vms->interactive);
+			if(option_debug > 2)
+				ast_log(LOG_DEBUG, "Using vm_state, interactive set to %d.\n",vms->interactive);
 			newmsgs = vms->newmessages++;
 			oldmsgs = vms->oldmessages;
 		} else {
-			ast_log(LOG_DEBUG, "About to call messagecount.\n");
 			res = count_messages_imap(ext, &newmsgs, &oldmsgs);
 			if(res < 0) {
 				ast_log(LOG_NOTICE,"Can not leave voicemail, unable to count messages\n");
@@ -3102,7 +3100,8 @@
 	if (box == 1) return 10;
 	/* get the real IMAP message number for this message */
 	sprintf(sequence,"%ld",vms->msgArray[msg]);
-	ast_log(LOG_DEBUG, "Copying sequence %s to mailbox %s\n",sequence,dbox);
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG, "Copying sequence %s to mailbox %s\n",sequence,dbox);
 	res = mail_copy(vms->mailstream,sequence,dbox);
 	if (res == 1) return 0;
 	return 1;
@@ -3723,8 +3722,6 @@
 	char todir[256], fn[256], ext_context[256], *stringp;
 	int newmsgs = 0, oldmsgs = 0;
 	const char *category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
-
-	ast_log(LOG_DEBUG, "In notify_new_message...\n");
 
 #ifdef IMAP_STORAGE
 	stpcpy(todir,TMP);
@@ -3938,14 +3935,15 @@
 #ifdef IMAP_STORAGE
  				/* NEED TO CHANGE username to mailbox!! - JAR */
  				/* Need to get message content */
- 				ast_log (LOG_DEBUG,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
+				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]);
+				header_content = mail_fetchheader (vms->mailstream, vms->msgArray[vms->curmsg]);
  				/* empty string means no valid header */
  				if (header_content == "" || header_content == NULL) {
  					ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@@ -3969,19 +3967,19 @@
  				}
  				if (!strcasecmp(fmt, "wav49"))
  					fmt = "WAV";
- 				
- 				ast_log (LOG_DEBUG,"**** format set to %s, vmfmts set to %s\n",fmt,vmfmts);
- 	        		/* ast_copy_string(fmt, vmfmts, sizeof(fmt));*/
+ 				if(option_debug > 2)
+	 				ast_log (LOG_DEBUG,"**** format set to %s, vmfmts set to %s\n",fmt,vmfmts);
+ 				/* ast_copy_string(fmt, vmfmts, sizeof(fmt));*/
  				/* if (!ast_strlen_zero(fmt)) { */
  
  				make_gsm_file(vms->fn, vms->imapuser, TMP, vms->curmsg);
- 
- 				ast_log (LOG_DEBUG,"Before mail_fetchstructure, message number is %ld, filename is:%s\n",vms->msgArray[vms->curmsg], vms->fn);
-   				/*mail_fetchstructure (mailstream, vmArray[0], &body); */
-   				mail_fetchstructure (vms->mailstream, vms->msgArray[vms->curmsg], &body);
-   				save_body(body,vms,"3","gsm");
+				if(option_debug > 2)
+	 				ast_log (LOG_DEBUG,"Before mail_fetchstructure, message number is %ld, filename is:%s\n",vms->msgArray[vms->curmsg], vms->fn);
+				/*mail_fetchstructure (mailstream, vmArray[0], &body); */
+				mail_fetchstructure (vms->mailstream, vms->msgArray[vms->curmsg], &body);
+				save_body(body,vms,"3","gsm");
  				/* should not assume "fmt" here! */
-   				save_body(body,vms,"2",fmt);
+				save_body(body,vms,"2",fmt);
  
  				char *myserveremail = serveremail;
  				if (!ast_strlen_zero(vmtmp->serveremail))
@@ -3997,10 +3995,9 @@
 				/* if (ast_play_and_wait(chan, "vm-savedto"))
 					break;
 				*/
-				snprintf(todir, sizeof(todir), "%s%s/%s/INBOX",  VM_SPOOL_DIR, vmtmp->context, vmtmp->mailbox);
+				snprintf(todir, sizeof(todir), "%s%s/%s/INBOX", VM_SPOOL_DIR, vmtmp->context, vmtmp->mailbox);
 				snprintf(sys, sizeof(sys), "mkdir -p %s\n", todir);
 				snprintf(ext_context, sizeof(ext_context), "%s@%s", vmtmp->mailbox, vmtmp->context);
-				ast_log(LOG_DEBUG, "%s", sys);
 				ast_safe_system(sys);
 		
 				res = count_messages(receiver, todir);
@@ -4020,11 +4017,9 @@
 					if (!strcasecmp(s, "wav49"))
 						s = "WAV";
 					snprintf(sys, sizeof(sys), "cp %s/msg%04d.%s %s/msg%04d.%s\n", dir, curmsg, s, todir, todircount, s);
-					ast_log(LOG_DEBUG, "%s", sys);
 					ast_safe_system(sys);
 				}
 				snprintf(sys, sizeof(sys), "cp %s/msg%04d.txt %s/msg%04d.txt\n", dir, curmsg, todir, todircount);
-				ast_log(LOG_DEBUG, "%s", sys);
 				ast_safe_system(sys);
 				snprintf(fn, sizeof(fn), "%s/msg%04d", todir,todircount);
 
@@ -4300,7 +4295,7 @@
 #ifdef IMAP_STORAGE
 static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms)
 {
-  	BODY *body;
+	BODY *body;
 	char *header_content;
 	char cid[256];
 	char context[256];
@@ -4312,15 +4307,15 @@
 	char *temp;
 
 	vms->starting = 0; 
-
-	ast_log (LOG_DEBUG,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
+	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]);
+	header_content = mail_fetchheader (vms->mailstream, vms->msgArray[vms->curmsg]);
 	/* empty string means no valid header */
 	if (header_content == "" || header_content == NULL) {
 		ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@@ -4329,10 +4324,8 @@
 
 	make_gsm_file(vms->fn, vms->imapuser,TMP, vms->curmsg);
 
-	ast_log (LOG_DEBUG,"Before mail_fetchstructure, message number is %ld, filename is:%s\n",vms->msgArray[vms->curmsg], vms->fn);
-
-  	mail_fetchstructure (vms->mailstream,vms->msgArray[vms->curmsg],&body);
-  	save_body(body,vms,"3","gsm");
+	mail_fetchstructure (vms->mailstream,vms->msgArray[vms->curmsg],&body);
+	save_body(body,vms,"3","gsm");
 
 	adsi_message(chan, vms);
 	if (!vms->curmsg)
@@ -4349,44 +4342,58 @@
 
 	/* Get info from headers!!  */
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Caller-ID-Num:");
-	if (temp != NULL) strcpy(cid,temp); else cid[0] = '\0';
-  	ast_log (LOG_DEBUG,"Caller id was set to: %s\n",cid);
+
+	if (temp != NULL)
+		strcpy(cid,temp); 
+	else 
+		cid[0] = '\0';
+
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Context:");
-	if (temp != NULL) strcpy(context,temp); else context[0] = '\0';
-  	ast_log (LOG_DEBUG,"Context was set to: %s\n",context);
+
+	if (temp != NULL)
+		strcpy(context,temp); 
+	else
+		context[0] = '\0';
+
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Orig-time:");
-	if (temp != NULL) strcpy(origtime,temp); else origtime[0] = '\0';
-  	ast_log (LOG_DEBUG,"Orig time was set to: %s\n",origtime);
+
+	if (temp != NULL)
+		strcpy(origtime,temp);
+	else
+		origtime[0] = '\0';
+
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Duration:");
-	if (temp != NULL) strcpy(duration,temp); else duration[0] = '\0';
-  	ast_log (LOG_DEBUG,"Duration was set to: %s\n",duration);
+
+	if (temp != NULL)
+		strcpy(duration,temp);
+	else
+		duration[0] = '\0';
+	
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Category:");
-	if (temp != NULL) strcpy(category,temp); else category[0] = '\0';
-  	ast_log (LOG_DEBUG,"Category was set to: %s\n",category);
+	
+	if (temp != NULL)
+		strcpy(category,temp);
+	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;
 
-	ast_log (LOG_DEBUG,"Before checks, res is %d\n",res);
 
 	/* What is the category thing?  JAR */
 	if ((!res) && category[0] != '\0' && category != NULL) {
 		res = play_message_category(chan, category);
-		ast_log (LOG_DEBUG,"category, res is %d, [0] is %c\n",res,category[0]);
 	}
 
 	if ((!res) && (ast_test_flag(vmu, VM_ENVELOPE)) && origtime[0] != '\0')
 		res = play_message_datetime(chan, vmu, origtime, "IMAP_STORAGE");
-	ast_log (LOG_DEBUG,"datetime, res is %d\n",res);
 	if ((!res) && (ast_test_flag(vmu, VM_SAYCID)) && cid[0] !='\0' && context[0] !='\0')
 		res = play_message_callerid(chan, vms, cid, context, 0);
-	ast_log (LOG_DEBUG,"callerid, res is %d\n",res);
-
-        if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)) && duration[0] != '\0')
-                res = play_message_duration(chan, vms, duration, vmu->saydurationm);
-	ast_log (LOG_DEBUG,"duration, res is %d\n",res);
+
+	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')
@@ -4395,14 +4402,11 @@
 	/*ast_config_destroy(msg_cfg);*/
 	res = 0;
 
-	ast_log (LOG_DEBUG,"Before play of message, res is %d\n",res);
 	if (!res) {
 		/* make_file(vms->fn, sizeof(vms->fn), TMP, vms->curmsg); */
-		ast_log (LOG_DEBUG,"About to play filename:%s\n",vms->fn);
 		vms->heard[vms->curmsg] = 1;
 		res = wait_file(chan, vms, vms->fn);
 	}
-	ast_log (LOG_DEBUG,"Before DISPOSE\n");
 	DISPOSE(vms->curdir, vms->curmsg);
 	return res;
 }
@@ -4508,8 +4512,8 @@
 #ifdef IMAP_STORAGE
 static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box)
 {
-  	SEARCHPGM *pgm;
-  	SEARCHHEADER *hdr;
+	SEARCHPGM *pgm;
+	SEARCHHEADER *hdr;
 	int ret;
 
 	strcpy(vms->imapuser,vmu->imapuser);
@@ -4535,24 +4539,23 @@
 	}
 	*/
 
-  	ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser);
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser);
 	ret = init_mailstream(vms);
 	if (ret != 0) {
-  		ast_log (LOG_ERROR,"Could not initialize mailstream\n");
+		ast_log (LOG_ERROR,"Could not initialize mailstream\n");
 		return -1;
 	}
 
 	/* Check Quota (here for now to test) */
-  	ast_log(LOG_DEBUG,"Checking QUOTA...\n");
 	mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota);
 	imap_getquotaroot(vms->mailstream,"INBOX");
 
-  	pgm = mail_newsearchpgm();
+	pgm = mail_newsearchpgm();
 
 	/* Check IMAP folder for Asterisk messages only... */
-  	ast_log(LOG_DEBUG,"setting search criteria - mailbox set to %s\n",vmu->mailbox);
-  	hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", vmu->mailbox);
-  	pgm->header = hdr;
+	hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", vmu->mailbox);
+	pgm->header = hdr;
 	pgm->deleted = 0;
 	pgm->undeleted = 1;
 
@@ -4566,9 +4569,9 @@
 	}
 
 	vms->vmArrayIndex = 0;
-
-  	ast_log(LOG_DEBUG,"Before mail_search_full, user is %s\n",vmu->imapuser);
-  	mail_search_full (vms->mailstream, NULL, pgm, NIL);
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG,"Before mail_search_full, user is %s\n",vmu->imapuser);
+	mail_search_full (vms->mailstream, NULL, pgm, NIL);
 
 
 	vms->lastmsg = vms->vmArrayIndex - 1;
@@ -4620,7 +4623,6 @@
 static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
 {
 	int x = 0;
-	ast_log(LOG_DEBUG,"Entering method...\n");
 	if (vms->lastmsg <= -1)
 		goto done;
 
@@ -4644,7 +4646,7 @@
 			} 
 		} else if (!strcasecmp(vms->curbox, "INBOX") && vms->heard[x] && !vms->deleted[x]) { 
 			/* Move to old folder before deleting */ 
-	        res = save_to_folder(vmu, vms, x, 1);
+			res = save_to_folder(vmu, vms, x, 1);
 			if (res == ERROR_LOCK_PATH) {
 				/* If save failed do not delete the message */
 				vms->deleted[x] = 0;
@@ -4664,10 +4666,11 @@
 	ast_unlock_path(vms->curdir);
 #else
 	for (x=0;x < vmu->maxmsg;x++) { 
-	    if (vms->deleted[x]) { 
-	    	ast_log(LOG_DEBUG,"IMAP delete of %d\n",x);
-		IMAP_DELETE(vms->curdir, x, vms->fn, vms);
-	    }
+		if (vms->deleted[x]) { 
+			if(option_debug > 2)
+				ast_log(LOG_DEBUG,"IMAP delete of %d\n",x);
+			IMAP_DELETE(vms->curdir, x, vms->fn, vms);
+		}
 	}
 #endif
 
@@ -6167,7 +6170,8 @@
 		}
 	}
 #ifdef IMAP_STORAGE
-		ast_log(LOG_DEBUG, "Checking quotas: comparing %u to %u\n",vms.quota_usage,vms.quota_limit);
+		if(option_debug > 2)
+			ast_log(LOG_DEBUG, "Checking quotas: comparing %u to %u\n",vms.quota_usage,vms.quota_limit);
 		if (vms.quota_usage >= vms.quota_limit) {
 			ast_log(LOG_DEBUG, "*** QUOTA EXCEEDED!!\n");
 			cmd = ast_play_and_wait(chan, "vm-mailboxfull");
@@ -6357,7 +6361,7 @@
 	
 		case '8':
 			if (vms.lastmsg > -1) {
-			    cmd = forward_message(chan, context, &vms, vmu, vmfmts, 0, record_gain);
+				cmd = forward_message(chan, context, &vms, vmu, vmfmts, 0, record_gain);
 				if (cmd == ERROR_LOCK_PATH) {
 					res = cmd;
 					goto out;
@@ -6375,13 +6379,13 @@
 				break;
 			} else if (cmd > 0) {
 				box = cmd = cmd - '0';
-		        	cmd = save_to_folder(vmu, &vms, vms.curmsg, cmd);
+				cmd = save_to_folder(vmu, &vms, vms.curmsg, cmd);
 				if (cmd == ERROR_LOCK_PATH) {
 					res = cmd;
 					goto out;
 #ifdef IMAP_STORAGE
 				} else if (cmd == 10) {
-				    goto out;
+					goto out;
 #endif
 				} else if (!cmd) {
 					vms.deleted[vms.curmsg] = 1;
@@ -6468,21 +6472,18 @@
 	}
 #ifdef IMAP_STORAGE
 	/* expunge message - use UID Expunge if supported on IMAP server*/
-	ast_log(LOG_DEBUG, "*** Checking if we can expunge, deleted set to %d, expungeonhangup set to %d\n",deleted,expungeonhangup);
+	if(option_debug > 2)
+		ast_log(LOG_DEBUG, "*** Checking if we can expunge, deleted set to %d, expungeonhangup set to %d\n",deleted,expungeonhangup);
 	if (vmu && deleted == 1 && expungeonhangup == 1)  {
 #ifdef HAVE_IMAP_TK2006
-	      	if (LEVELUIDPLUS (vms.mailstream)) {
-			ast_log(LOG_DEBUG, "*** About to expunge messages using UID\n");
+		if (LEVELUIDPLUS (vms.mailstream)) {
 			mail_expunge_full(vms.mailstream,NIL,EX_UID);
 		} else 
 #endif
-		{
-			ast_log(LOG_DEBUG, "*** About to expunge messages\n");
 			mail_expunge(vms.mailstream);
-		}
 	}
 	/*  before we delete the state, we should copy pertainent info
-            back to the persistent model */
+	 *  back to the persistent model */
 	vmstate_delete(&vms);
 #endif
 	if (vmu)
@@ -7456,14 +7457,15 @@
 #ifdef IMAP_STORAGE
 	/* START HERE */
 	/* get the message info!! */
-	ast_log (LOG_DEBUG,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
+	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]);
+	header_content = mail_fetchheader (vms->mailstream, vms->msgArray[vms->curmsg]);
 	/* empty string means no valid header */
 	if (header_content == "" || header_content == NULL) {
 		ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@@ -7472,17 +7474,29 @@
 
 	/* Get info from headers!!  */
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Caller-ID-Num:");
-	if (temp != NULL) strcpy(cidS,temp); else cidS[0] = '\0';
+	
+	if (temp != NULL)
+		strcpy(cidS,temp);
+	else
+		cidS[0] = '\0';
+	
 	cid = &cidS[0];
-  	ast_log (LOG_DEBUG,"Caller id was set to: %s\n",cid);
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Context:");
-	if (temp != NULL) strcpy(contextS,temp); else contextS[0] = '\0';
+	
+	if (temp != NULL)
+		strcpy(contextS,temp);
+	else
+		contextS[0] = '\0';
+	
 	context = &contextS[0];
-  	ast_log (LOG_DEBUG,"Context was set to: %s\n",context);
 	temp = get_header_by_tag(header_content, "X-Asterisk-VM-Orig-time:");
-	if (temp != NULL) strcpy(origtimeS,temp); else origtimeS[0] = '\0';
+	
+	if (temp != NULL)
+		strcpy(origtimeS,temp);
+	else
+		origtimeS[0] = '\0';
+	
 	origtime = &origtimeS[0];
-  	ast_log (LOG_DEBUG,"Orig time was set to: %s\n",origtime);
 
 	filename = "IMAP_STORAGE";
 #else
@@ -7845,7 +7859,7 @@
 			}
 		}
 	}
-	if (outsidecaller)  
+	if (outsidecaller)
 		ast_play_and_wait(chan, "vm-goodbye");
 	if (cmd == 't')
 		cmd = 0;
@@ -7854,7 +7868,7 @@
 
 #ifdef IMAP_STORAGE
  
-int init_mailstream (struct vm_state *vms)
+static int init_mailstream(struct vm_state *vms)
 {
 	MAILSTREAM *stream = NIL;
 	/* char *s; */
@@ -7867,7 +7881,8 @@
 		ast_log (LOG_ERROR,"vm_state is NULL!\n");
 		return -1;
 	}
-	ast_log (LOG_DEBUG,"vm_state user is:%s\n",vms->imapuser);
+	if(option_debug > 2)
+		ast_log (LOG_DEBUG,"vm_state user is:%s\n",vms->imapuser);
 	if (vms->mailstream == NIL || vms->mailstream == NULL) {
 		ast_log (LOG_DEBUG,"mailstream not set.\n");
 	} else {
@@ -7885,14 +7900,13 @@
 	} else {
 		snprintf(mbox, sizeof(mbox), "{%s:%s/imap/%s/user=%s}%s",imapserver,imapport,imapflags,vms->imapuser,vms->curbox);
 	}
-	ast_log (LOG_DEBUG,"Before mail_open, curusr: %s, mbox:%s\n",curusr,mbox);
+	if(option_debug > 2)
+		ast_log (LOG_DEBUG,"Before mail_open, curusr: %s, mbox:%s\n",curusr,mbox);
 	vms->mailstream = mail_open (stream, mbox, debug ? OP_DEBUG : NIL);
-	ast_log (LOG_DEBUG,"After mail_open\n");
 	if (vms->mailstream == NIL) {
 		return -1;
 	} else {
 		if (delimiter == '\0') {
-			ast_log (LOG_DEBUG,"Calling get_mailbox_delimiter...\n");
 			get_mailbox_delimiter(vms->mailstream);
 		}
 		/* status(vms->mailstream); */
@@ -7900,7 +7914,7 @@
 	}
 }
 
-void write_file (char *filename, char *buffer, unsigned long len)
+static void write_file(char *filename, char *buffer, unsigned long len)
 {
 	FILE *output;
 
@@ -7909,19 +7923,18 @@
 	fclose (output);
 }
 
-void mm_searched (MAILSTREAM *stream, unsigned long number)
+void mm_searched(MAILSTREAM *stream, unsigned long number)
 {
 	struct vm_state *vms;
 	char *mailbox;
 	char *user;
-	ast_log (LOG_DEBUG, "Callback for message %ld\n", number);
 	mailbox = stream->mailbox;
 	user = get_user_by_mailbox(mailbox);
-	ast_log (LOG_DEBUG, "User is %s\n",user);
 	
 	vms = get_vm_state_by_imapuser(user,2);
 	if (vms != NULL) {
-		ast_log (LOG_DEBUG, "saving mailbox message number %lu as message %d. Interactive set to %d\n",number,vms->vmArrayIndex,vms->interactive);
+		if(option_debug > 2)
+			ast_log (LOG_DEBUG, "saving mailbox message number %lu as message %d. Interactive set to %d\n",number,vms->vmArrayIndex,vms->interactive);
 		vms->msgArray[vms->vmArrayIndex++] = number;
 	} else {
 		ast_log (LOG_ERROR, "No state found.\n");
@@ -7934,7 +7947,7 @@
  *	    prefix string
  *	    index
  */
-void display_body (BODY *body, char *pfx, long i)
+static void display_body(BODY *body, char *pfx, long i)
 {
 	char tmp[MAILTMPLEN];
 	char *s = tmp;
@@ -7987,7 +8000,7 @@
 /* MM status report
  * Accepts: MAIL stream
  */
-void status (MAILSTREAM *stream)
+static void status(MAILSTREAM *stream)
 {
 	unsigned long i;
 	char *s, date[MAILTMPLEN];
@@ -8096,65 +8109,68 @@
 
 /* Interfaces to C-client */
 
-void mm_exists (MAILSTREAM * stream, unsigned long number)
+void mm_exists(MAILSTREAM * stream, unsigned long number)
 {
 	/* mail_ping will callback here if new mail! */
-	ast_log (LOG_DEBUG, "Entering EXISTS callback for message %ld\n", number);
+	if(option_debug > 3)
+		ast_log (LOG_DEBUG, "Entering EXISTS callback for message %ld\n", number);
 	if (number == 0) return;
 	set_update(stream);
 }
 
 
-void mm_expunged (MAILSTREAM * stream, unsigned long number)
+void mm_expunged(MAILSTREAM * stream, unsigned long number)
 {
 	/* mail_ping will callback here if expunged mail! */
-	ast_log (LOG_DEBUG, "Entering EXPUNGE callback for message %ld\n", number);
+	if(option_debug > 3)
+		ast_log (LOG_DEBUG, "Entering EXPUNGE callback for message %ld\n", number);
 	if (number == 0) return;
 	set_update(stream);
 }
 
 
-void mm_flags (MAILSTREAM * stream, unsigned long number)
+void mm_flags(MAILSTREAM * stream, unsigned long number)
 {
 	/* mail_ping will callback here if read mail! */
-	ast_log (LOG_DEBUG, "Entering FLAGS callback for message %ld\n", number);
+	if(option_debug > 3)
+		ast_log (LOG_DEBUG, "Entering FLAGS callback for message %ld\n", number);
 	if (number == 0) return;
 	set_update(stream);
 }
 
 
-void mm_notify (MAILSTREAM * stream, char *string, long errflg)
+void mm_notify(MAILSTREAM * stream, char *string, long errflg)
 {
 	mm_log (string, errflg);
 }
 
 
-void mm_list (MAILSTREAM * stream, int delim, char *mailbox, long attributes)
-{
-	  ast_log (LOG_NOTICE,"****** Entering callback\n");
-	  putchar (' ');
-	  if (delimiter) {
-		  putchar (delimiter);
-		  delimiter = delim;
-		  ast_log (LOG_NOTICE,"Delimiter set to %c\n",delim);
-	  } else {
-		  fputs ("NIL", stdout);
-	  }
-	  putchar (' ');
-	  fputs (mailbox, stdout);
-	  if (attributes & LATT_NOINFERIORS)
-		  fputs (", no inferiors", stdout);
-	  if (attributes & LATT_NOSELECT)
-		  fputs (", no select", stdout);
-	  if (attributes & LATT_MARKED)
-		  fputs (", marked", stdout);
-	  if (attributes & LATT_UNMARKED)
-		  fputs (", unmarked", stdout);
-	  putchar ('\n');
-}
-
-
-void mm_lsub (MAILSTREAM * stream, int delimiter, char *mailbox, long attributes)
+void mm_list(MAILSTREAM * stream, int delim, char *mailbox, long attributes)
+{
+	ast_log (LOG_NOTICE,"****** Entering callback\n");
+	putchar (' ');
+	if (delimiter) {
+		putchar (delimiter);
+		delimiter = delim;
+		ast_log (LOG_NOTICE,"Delimiter set to %c\n",delim);
+	} else {
+		fputs ("NIL", stdout);
+	}
+	putchar (' ');
+	fputs (mailbox, stdout);
+	if (attributes & LATT_NOINFERIORS)
+		fputs (", no inferiors", stdout);
+	if (attributes & LATT_NOSELECT)
+		fputs (", no select", stdout);
+	if (attributes & LATT_MARKED)
+		fputs (", marked", stdout);
+	if (attributes & LATT_UNMARKED)
+		fputs (", unmarked", stdout);
+	putchar ('\n');
+}
+
+
+void mm_lsub(MAILSTREAM * stream, int delimiter, char *mailbox, long attributes)
 {
 	putchar (' ');
 	if (delimiter)
@@ -8175,7 +8191,7 @@
 }
 
 
-void mm_status (MAILSTREAM * stream, char *mailbox, MAILSTATUS * status)
+void mm_status(MAILSTREAM * stream, char *mailbox, MAILSTATUS * status)
 {
 	ast_log (LOG_NOTICE," Mailbox %s", mailbox);
 	if (status->flags & SA_MESSAGES)
@@ -8192,11 +8208,12 @@
 }
 
 
-void mm_log (char *string, long errflg)
+void mm_log(char *string, long errflg)
 {
 	switch ((short) errflg) {
 		case NIL:
-			ast_log(LOG_DEBUG,"IMAP Info: %s\n", string);
+			if(option_debug)
+				ast_log(LOG_DEBUG,"IMAP Info: %s\n", string);
 			break;
 		case PARSE:
 		case WARN:
@@ -8209,16 +8226,17 @@
 }
 
 
-void mm_dlog (char *string)
+void mm_dlog(char *string)
 {
 	ast_log (LOG_NOTICE,string);
 }
 
 
-void mm_login (NETMBX * mb, char *user, char *pwd, long trial)
+void mm_login(NETMBX * mb, char *user, char *pwd, long trial)
 {
 	char tmp[MAILTMPLEN];
-	ast_log(LOG_DEBUG, "Entering callback...\n");
+	if(option_debug > 3)
+		ast_log(LOG_DEBUG, "Entering callback mm_login\n");
 	if (curhst)
 		fs_give ((void **) &curhst);
 	curhst = (char *) fs_get (1 + strlen (mb->host));
@@ -8236,38 +8254,35 @@
 	/* strcpy (pwd, getpass (tmp));*/
 	/* We should only do this when necessary */
 	if (strlen(authpassword) > 0) {
-		ast_log(LOG_DEBUG, "Setting password.\n");
 		strcpy (pwd, authpassword);
 	}
-	
-	ast_log(LOG_DEBUG, "Returning from callback...\n");
-}
-
-
-void mm_critical (MAILSTREAM * stream)
-{
-}
-
-
-void mm_nocritical (MAILSTREAM * stream)
-{
-}
-
-
-long mm_diskerror (MAILSTREAM * stream, long errcode, long serious)
+}
+
+
+void mm_critical(MAILSTREAM * stream)
+{
+}
+
+
+void mm_nocritical(MAILSTREAM * stream)
+{
+}
+
+
+long mm_diskerror(MAILSTREAM * stream, long errcode, long serious)
 {
 	kill (getpid (), SIGSTOP);
 	return NIL;
 }
 
 
-void mm_fatal (char *string)
+void mm_fatal(char *string)
 {
 	ast_log(LOG_ERROR,"IMAP access FATAL error: %s\n", string);
 }
 
 /* C-client callback to handle quota */
-void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota)
+static void mm_parsequota(MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota)
 {
 	struct vm_state *vms;
 	char *mailbox;
@@ -8285,7 +8300,8 @@
 	user = get_user_by_mailbox(mailbox);
 	vms = get_vm_state_by_imapuser(user,2);
 	if (vms != NULL) {
-		ast_log (LOG_DEBUG, "User %s usage is %lu, limit is %lu\n",user,usage,limit);
+		if(option_debug > 2)
+			ast_log (LOG_DEBUG, "User %s usage is %lu, limit is %lu\n",user,usage,limit);
 		vms->quota_usage = usage;
 		vms->quota_limit = limit;
 	} else {
@@ -8293,7 +8309,7 @@
 	}
 }
 
-static char * get_header_by_tag(char *header, char *tag)
+static char *get_header_by_tag(char *header, char *tag)
 {
 	char *start;
 	int taglen;
@@ -8313,7 +8329,7 @@
 	return temp;
 }
 
-static char * get_user_by_mailbox(char *mailbox)
+static char *get_user_by_mailbox(char *mailbox)
 {
 	char *start, *quote;
 	char *eol_pnt;
@@ -8341,60 +8357,65 @@
 	}
 }
 
-static struct vm_state * get_vm_state_by_imapuser(char *user, int interactive)
-{ 
-        struct vmstate *vlist = NULL;
-
-        vlist = vmstates;
-	/* ast_log(LOG_DEBUG, "user set to:%s\n",user); */
-        while (vlist) {
-                if (vlist->vms != NULL) {
-                    if (vlist->vms->imapuser != NULL) {
-			/* ast_log(LOG_DEBUG, "	comparing user %s to vmstate user %s\n",user,vlist->vms->imapuser); */
-			if (strcmp(vlist->vms->imapuser,user) == 0) {
-				if (interactive == 2) {
-					/* ast_log(LOG_DEBUG, "Interactive set to ANY, current is: %d\n",vlist->vms->interactive); */
-                        		return vlist->vms;
-				} else if (vlist->vms->interactive == interactive) {
-					/* ast_log(LOG_DEBUG, "	Found it!\n"); */
-                        		return vlist->vms;
+static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive)
+{
+	struct vmstate *vlist = NULL;
+
+	vlist = vmstates;
+	while (vlist) {
+		if (vlist->vms != NULL) {
+			if (vlist->vms->imapuser != NULL) {
+				if (strcmp(vlist->vms->imapuser,user) == 0) {
+					if (interactive == 2) {
+						return vlist->vms;
+					} else if (vlist->vms->interactive == interactive) {
+						return vlist->vms;
+					}
 				}
-			}
-                    } else {
-			ast_log(LOG_DEBUG, "	error: imapuser is NULL for %s\n",user);
-		    }
-                } else {
-			ast_log(LOG_DEBUG, "	error: vms is NULL for %s\n",user);
-		}
-                vlist = vlist->next;
-        }
-	ast_log(LOG_DEBUG, "%s not found in vmstates\n",user);
+			} else {
+				if(option_debug > 2)
+					ast_log(LOG_DEBUG, "	error: imapuser is NULL for %s\n",user);
+			}
+		} else {

[... 303 lines stripped ...]


More information about the asterisk-commits mailing list