whitespace clean up

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@41715 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Matt O'Gorman 2006-09-01 17:20:48 +00:00
parent b4d0f26d2b
commit c13e44eacb
1 changed files with 186 additions and 149 deletions

View File

@ -89,8 +89,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#endif #endif
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
char *curhst = NIL; /* currently connected host */ char *curhst = NIL;/* currently connected host */
char *curusr = NIL; /* current login user */ char *curusr = NIL;/* current login user */
char temp[1024]; char temp[1024];
@ -126,8 +126,8 @@ void mm_parsequota (MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pquota);
/* should define TMP in config file... */ /* should define TMP in config file... */
#define TMP "/tmp" #define TMP "/tmp"
struct vmstate { struct vmstate {
struct vm_state *vms; struct vm_state *vms;
struct vmstate *next; struct vmstate *next;
}; };
AST_MUTEX_DEFINE_STATIC(vmstate_lock); AST_MUTEX_DEFINE_STATIC(vmstate_lock);
static struct vmstate *vmstates = NULL; static struct vmstate *vmstates = NULL;
@ -309,7 +309,7 @@ struct ast_vm_user {
int saydurationm; int saydurationm;
int maxmsg; /*!< Maximum number of msgs per folder for this mailbox */ int maxmsg; /*!< Maximum number of msgs per folder for this mailbox */
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
char imapuser[80]; /* IMAP server login */ char imapuser[80]; /* IMAP server login */
#endif #endif
double volgain; /*!< Volume gain for voicemails sent via email */ double volgain; /*!< Volume gain for voicemails sent via email */
AST_LIST_ENTRY(ast_vm_user) list; AST_LIST_ENTRY(ast_vm_user) list;
@ -910,8 +910,8 @@ static void vm_imap_delete(int msgnum, struct vm_state *vms)
} }
ast_log(LOG_DEBUG, "deleting msgnum %d, which is mailbox message %lu\n",msgnum,messageNum); ast_log(LOG_DEBUG, "deleting msgnum %d, which is mailbox message %lu\n",msgnum,messageNum);
/* delete message */ /* delete message */
sprintf (arg,"%lu",messageNum); sprintf (arg,"%lu",messageNum);
mail_setflag (vms->mailstream,arg,"\\DELETED"); mail_setflag (vms->mailstream,arg,"\\DELETED");
} }
#endif #endif
@ -1992,14 +1992,13 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c
/* only attach if necessary */ /* only attach if necessary */
ast_log(LOG_DEBUG, "Before second attachment with format set to:%s\n",format); ast_log(LOG_DEBUG, "Before second attachment with format set to:%s\n",format);
if (strcmp(format, "gsm")) { if (strcmp(format, "gsm")) {
fprintf(p, "--%s\n", bound); fprintf(p, "--%s\n", bound);
fprintf(p, "Content-Type: audio/x-gsm; name=\"msg%04d.%s\"\n", msgnum, format); fprintf(p, "Content-Type: audio/x-gsm; name=\"msg%04d.%s\"\n", msgnum, format);
fprintf(p, "Content-Transfer-Encoding: base64\n"); fprintf(p, "Content-Transfer-Encoding: base64\n");
fprintf(p, "Content-Description: Voicemail sound attachment.\n"); fprintf(p, "Content-Description: Voicemail sound attachment.\n");
fprintf(p, "Content-Disposition: attachment; filename=\"msg%04d.gsm\"\n\n", msgnum); fprintf(p, "Content-Disposition: attachment; filename=\"msg%04d.gsm\"\n\n", msgnum);
snprintf(fname, sizeof(fname), "%s.gsm", attach);
snprintf(fname, sizeof(fname), "%s.gsm", attach); base_encode(fname, p);
base_encode(fname, p);
} }
#endif #endif
fprintf(p, "\n\n--%s--\n.\n", bound); fprintf(p, "\n\n--%s--\n.\n", bound);
@ -2151,13 +2150,13 @@ static const char *mbox(int id)
static const char *msgs[] = { static const char *msgs[] = {
"INBOX", "INBOX",
"Old", "Old",
"Work", "Work",
"Family", "Family",
"Friends", "Friends",
"Cust1", "Cust1",
"Cust2", "Cust2",
"Cust3", "Cust3",
"Cust4", "Cust4",
"Cust5", "Cust5",
}; };
return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown"; return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
@ -2187,10 +2186,10 @@ static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
ast_copy_string(tmp, mailbox, sizeof(tmp)); ast_copy_string(tmp, mailbox, sizeof(tmp));
context = strchr(tmp, '@'); context = strchr(tmp, '@');
if (context) { if (context) {
*context = '\0'; *context = '\0';
context++; context++;
} else } else
context = "default"; context = "default";
obj = odbc_request_obj(odbc_database, 0); obj = odbc_request_obj(odbc_database, 0);
@ -2302,7 +2301,7 @@ static int messagecount(const char *context, const char *mailbox, const char *fo
} }
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder); 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); 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); ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt);
goto yuck; goto yuck;
@ -2355,8 +2354,8 @@ static int has_voicemail(const char *mailbox, const char *folder)
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs) static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
{ {
SEARCHPGM *pgm; SEARCHPGM *pgm;
SEARCHHEADER *hdr; SEARCHHEADER *hdr;
struct ast_vm_user *vmu; struct ast_vm_user *vmu;
struct vm_state *vms_p; struct vm_state *vms_p;
@ -2406,15 +2405,15 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
} }
/* We have to get the user before we can open the stream! */ /* 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); vmu = find_user(NULL, context, mailboxnc);
if (vmu == NULL) { 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; return -1;
} else { } else {
/* No IMAP account available */ /* No IMAP account available */
if (vmu->imapuser[0] == '\0') { 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; return -1;
} }
} }
@ -2425,7 +2424,7 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
vms_p = get_vm_state_by_mailbox(mailboxnc,1); vms_p = get_vm_state_by_mailbox(mailboxnc,1);
} }
if (vms_p != NULL) { if (vms_p != NULL) {
ast_log (LOG_DEBUG,"Returning before search - user is logged in\n"); ast_log (LOG_DEBUG,"Returning before search - user is logged in\n");
*newmsgs = vms_p->newmessages; *newmsgs = vms_p->newmessages;
*oldmsgs = vms_p->oldmessages; *oldmsgs = vms_p->oldmessages;
return 0; return 0;
@ -2438,12 +2437,12 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
} }
if (vms_p == NULL) { if (vms_p == NULL) {
ast_log (LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser); ast_log (LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser);
vms_p = (struct vm_state *)malloc(sizeof(struct vm_state)); vms_p = (struct vm_state *)malloc(sizeof(struct vm_state));
strcpy(vms_p->imapuser,vmu->imapuser); strcpy(vms_p->imapuser,vmu->imapuser);
strcpy(vms_p->username,mailboxnc); /* save for access from interactive entry point */ strcpy(vms_p->username,mailboxnc); /* save for access from interactive entry point */
vms_p->mailstream = NIL; /* 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); ast_log (LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
vms_p->updated = 1; vms_p->updated = 1;
vms_p->interactive = 0; vms_p->interactive = 0;
/* set mailbox to INBOX! */ /* set mailbox to INBOX! */
@ -2454,13 +2453,13 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
if (vms_p->mailstream == NULL) if (vms_p->mailstream == NULL)
ret = init_mailstream(vms_p); ret = init_mailstream(vms_p);
if (vms_p->mailstream == NULL) { 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; return -1;
} }
if (newmsgs && ret==0 && vms_p->updated==1 ) { if (newmsgs && ret==0 && vms_p->updated==1 ) {
pgm = mail_newsearchpgm (); pgm = mail_newsearchpgm ();
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc); hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
pgm->header = hdr; pgm->header = hdr;
pgm->unseen = 1; pgm->unseen = 1;
pgm->seen = 0; pgm->seen = 0;
pgm->undeleted = 1; pgm->undeleted = 1;
@ -2468,17 +2467,17 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
vms_p->vmArrayIndex = 0; vms_p->vmArrayIndex = 0;
ast_log (LOG_DEBUG,"Before search of mailbox %s for NEW messages\n",vms_p->mailstream->mailbox); 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); mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
ast_log (LOG_DEBUG,"After search\n"); ast_log (LOG_DEBUG,"After search\n");
*newmsgs = vms_p->vmArrayIndex; *newmsgs = vms_p->vmArrayIndex;
vms_p->newmessages = vms_p->vmArrayIndex; vms_p->newmessages = vms_p->vmArrayIndex;
ast_log (LOG_DEBUG,"There are %d NEW messages\n",vms_p->newmessages); ast_log (LOG_DEBUG,"There are %d NEW messages\n",vms_p->newmessages);
} }
if (oldmsgs && ret==0 && vms_p->updated==1 ) { if (oldmsgs && ret==0 && vms_p->updated==1 ) {
pgm = mail_newsearchpgm (); pgm = mail_newsearchpgm ();
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc); hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
pgm->header = hdr; pgm->header = hdr;
pgm->unseen = 0; pgm->unseen = 0;
pgm->seen = 1; pgm->seen = 1;
pgm->deleted = 0; pgm->deleted = 0;
@ -2486,18 +2485,18 @@ static int count_messages_imap(const char *mailbox, int *newmsgs, int *oldmsgs)
vms_p->vmArrayIndex = 0; vms_p->vmArrayIndex = 0;
ast_log (LOG_DEBUG,"Before search of mailbox %s for OLD messages\n",vms_p->mailstream->mailbox); 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; *oldmsgs = vms_p->vmArrayIndex;
vms_p->oldmessages = vms_p->vmArrayIndex; vms_p->oldmessages = vms_p->vmArrayIndex;
ast_log (LOG_DEBUG,"There are %d OLD messages\n",vms_p->oldmessages); 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 */ if (vms_p->updated == 1) { /* changes, so we did the searches above */
vms_p->updated = 0; vms_p->updated = 0;
} else if (vms_p->updated > 1) { /* decrement delay count */ } else if (vms_p->updated > 1) { /* decrement delay count */
vms_p->updated--; vms_p->updated--;
} else { /* no changes, so don't search */ } else { /* no changes, so don't search */
ast_log (LOG_DEBUG,"Calling mail_ping on mailbox %s\n",vms_p->mailstream->mailbox); ast_log (LOG_DEBUG,"Calling mail_ping on mailbox %s\n",vms_p->mailstream->mailbox);
mail_ping(vms_p->mailstream); mail_ping(vms_p->mailstream);
/* Keep the old data */ /* Keep the old data */
*newmsgs = vms_p->newmessages; *newmsgs = vms_p->newmessages;
@ -2518,7 +2517,7 @@ static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int i
ast_log(LOG_NOTICE, "Copying message from %s@%s to %s@%s\n", vmu->mailbox, vmu->context, recip->mailbox, recip->context); 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"); create_dirpath(todir, sizeof(todir), recip->context, recip->mailbox, "INBOX");
make_dir(fromdir, sizeof(fromdir), vmu->context, vmu->mailbox, frombox); make_dir(fromdir, sizeof(fromdir), vmu->context, vmu->mailbox, frombox);
make_file(frompath, sizeof(frompath), fromdir, msgnum); make_file(frompath, sizeof(frompath), fromdir, msgnum);
@ -2701,7 +2700,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
char callerid[256]; char callerid[256];
FILE *txt; FILE *txt;
char date[256]; char date[256];
int txtdes; int txtdes;
#endif #endif
int res = 0; int res = 0;
int msgnum; int msgnum;
@ -2783,11 +2782,11 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
if (!ast_strlen_zero(vmu->exit)) { if (!ast_strlen_zero(vmu->exit)) {
if (ast_exists_extension(chan, vmu->exit, "a", 1, chan->cid.cid_num)) 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)) } 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)) { 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; ausemacro = 1;
} }
@ -2824,7 +2823,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
if (res > 0) if (res > 0)
ast_stopstream(chan); ast_stopstream(chan);
/* Check for a '*' here in case the caller wants to escape from voicemail to something /* 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 == '*') { if (res == '*') {
chan->exten[0] = 'a'; chan->exten[0] = 'a';
chan->exten[1] = '\0'; chan->exten[1] = '\0';
@ -3945,7 +3944,7 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
} }
/* This will only work for new messages... */ /* 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 */ /* empty string means no valid header */
if (header_content == "" || header_content == NULL) { if (header_content == "" || header_content == NULL) {
ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]); ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@ -3971,17 +3970,17 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
fmt = "WAV"; fmt = "WAV";
ast_log (LOG_DEBUG,"**** format set to %s, vmfmts set to %s\n",fmt,vmfmts); ast_log (LOG_DEBUG,"**** format set to %s, vmfmts set to %s\n",fmt,vmfmts);
/* ast_copy_string(fmt, vmfmts, sizeof(fmt));*/ /* ast_copy_string(fmt, vmfmts, sizeof(fmt));*/
/* if (!ast_strlen_zero(fmt)) { */ /* if (!ast_strlen_zero(fmt)) { */
make_gsm_file(vms->fn, vms->imapuser, TMP, vms->curmsg); 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); 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 (mailstream, vmArray[0], &body); */
mail_fetchstructure (vms->mailstream, vms->msgArray[vms->curmsg], &body); mail_fetchstructure (vms->mailstream, vms->msgArray[vms->curmsg], &body);
save_body(body,vms,"3","gsm"); save_body(body,vms,"3","gsm");
/* should not assume "fmt" here! */ /* should not assume "fmt" here! */
save_body(body,vms,"2",fmt); save_body(body,vms,"2",fmt);
char *myserveremail = serveremail; char *myserveremail = serveremail;
if (!ast_strlen_zero(vmtmp->serveremail)) if (!ast_strlen_zero(vmtmp->serveremail))
@ -3997,7 +3996,7 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
/* if (ast_play_and_wait(chan, "vm-savedto")) /* if (ast_play_and_wait(chan, "vm-savedto"))
break; 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(sys, sizeof(sys), "mkdir -p %s\n", todir);
snprintf(ext_context, sizeof(ext_context), "%s@%s", vmtmp->mailbox, vmtmp->context); snprintf(ext_context, sizeof(ext_context), "%s@%s", vmtmp->mailbox, vmtmp->context);
ast_log(LOG_DEBUG, "%s", sys); ast_log(LOG_DEBUG, "%s", sys);
@ -4300,7 +4299,7 @@ static int play_message_duration(struct ast_channel *chan, struct vm_state *vms,
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms) 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 *header_content;
char cid[256]; char cid[256];
char context[256]; char context[256];
@ -4320,7 +4319,7 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
} }
/* This will only work for new messages... */ /* 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 */ /* empty string means no valid header */
if (header_content == "" || header_content == NULL) { if (header_content == "" || header_content == NULL) {
ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]); ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@ -4331,8 +4330,8 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
ast_log (LOG_DEBUG,"Before mail_fetchstructure, message number is %ld, filename is:%s\n",vms->msgArray[vms->curmsg], vms->fn); 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); mail_fetchstructure (vms->mailstream,vms->msgArray[vms->curmsg],&body);
save_body(body,vms,"3","gsm"); save_body(body,vms,"3","gsm");
adsi_message(chan, vms); adsi_message(chan, vms);
if (!vms->curmsg) if (!vms->curmsg)
@ -4349,20 +4348,44 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
/* Get info from headers!! */ /* Get info from headers!! */
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Caller-ID-Num:"); 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';
ast_log (LOG_DEBUG,"Caller id was set to: %s\n",cid);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Context:"); 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';
ast_log (LOG_DEBUG,"Context was set to: %s\n",context);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Orig-time:"); 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';
ast_log (LOG_DEBUG,"Orig time was set to: %s\n",origtime);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Duration:"); 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';
ast_log (LOG_DEBUG,"Duration was set to: %s\n",duration);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Category:"); 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';
ast_log (LOG_DEBUG,"Category was set to: %s\n",category);
/*if (!strncasecmp("macro",context,5)) Macro names in contexts are useless for our needs */ /*if (!strncasecmp("macro",context,5)) Macro names in contexts are useless for our needs */
/* context = ast_variable_retrieve(msg_cfg, "message","macrocontext"); */ /* context = ast_variable_retrieve(msg_cfg, "message","macrocontext"); */
@ -4384,8 +4407,8 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
res = play_message_callerid(chan, vms, cid, context, 0); res = play_message_callerid(chan, vms, cid, context, 0);
ast_log (LOG_DEBUG,"callerid, res is %d\n",res); ast_log (LOG_DEBUG,"callerid, res is %d\n",res);
if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)) && duration[0] != '\0') if ((!res) && (ast_test_flag(vmu, VM_SAYDURATION)) && duration[0] != '\0')
res = play_message_duration(chan, vms, duration, vmu->saydurationm); res = play_message_duration(chan, vms, duration, vmu->saydurationm);
ast_log (LOG_DEBUG,"duration, res is %d\n",res); ast_log (LOG_DEBUG,"duration, res is %d\n",res);
/* Allow pressing '1' to skip envelope / callerid */ /* Allow pressing '1' to skip envelope / callerid */
@ -4508,8 +4531,8 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
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)
{ {
SEARCHPGM *pgm; SEARCHPGM *pgm;
SEARCHHEADER *hdr; SEARCHHEADER *hdr;
int ret; int ret;
strcpy(vms->imapuser,vmu->imapuser); strcpy(vms->imapuser,vmu->imapuser);
@ -4535,24 +4558,24 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box)
} }
*/ */
ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser); ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser);
ret = init_mailstream(vms); ret = init_mailstream(vms);
if (ret != 0) { if (ret != 0) {
ast_log (LOG_ERROR,"Could not initialize mailstream\n"); ast_log (LOG_ERROR,"Could not initialize mailstream\n");
return -1; return -1;
} }
/* Check Quota (here for now to test) */ /* Check Quota (here for now to test) */
ast_log(LOG_DEBUG,"Checking QUOTA...\n"); ast_log(LOG_DEBUG,"Checking QUOTA...\n");
mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota); mail_parameters(NULL, SET_QUOTA, (void *) mm_parsequota);
imap_getquotaroot(vms->mailstream,"INBOX"); imap_getquotaroot(vms->mailstream,"INBOX");
pgm = mail_newsearchpgm(); pgm = mail_newsearchpgm();
/* Check IMAP folder for Asterisk messages only... */ /* Check IMAP folder for Asterisk messages only... */
ast_log(LOG_DEBUG,"setting search criteria - mailbox set to %s\n",vmu->mailbox); ast_log(LOG_DEBUG,"setting search criteria - mailbox set to %s\n",vmu->mailbox);
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", vmu->mailbox); hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", vmu->mailbox);
pgm->header = hdr; pgm->header = hdr;
pgm->deleted = 0; pgm->deleted = 0;
pgm->undeleted = 1; pgm->undeleted = 1;
@ -4567,8 +4590,8 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box)
vms->vmArrayIndex = 0; vms->vmArrayIndex = 0;
ast_log(LOG_DEBUG,"Before mail_search_full, user is %s\n",vmu->imapuser); ast_log(LOG_DEBUG,"Before mail_search_full, user is %s\n",vmu->imapuser);
mail_search_full (vms->mailstream, NULL, pgm, NIL); mail_search_full (vms->mailstream, NULL, pgm, NIL);
vms->lastmsg = vms->vmArrayIndex - 1; vms->lastmsg = vms->vmArrayIndex - 1;
@ -4644,7 +4667,7 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
} }
} else if (!strcasecmp(vms->curbox, "INBOX") && vms->heard[x] && !vms->deleted[x]) { } else if (!strcasecmp(vms->curbox, "INBOX") && vms->heard[x] && !vms->deleted[x]) {
/* Move to old folder before deleting */ /* 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 (res == ERROR_LOCK_PATH) {
/* If save failed do not delete the message */ /* If save failed do not delete the message */
vms->deleted[x] = 0; vms->deleted[x] = 0;
@ -4664,10 +4687,10 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
ast_unlock_path(vms->curdir); ast_unlock_path(vms->curdir);
#else #else
for (x=0;x < vmu->maxmsg;x++) { for (x=0;x < vmu->maxmsg;x++) {
if (vms->deleted[x]) { if (vms->deleted[x]) {
ast_log(LOG_DEBUG,"IMAP delete of %d\n",x); ast_log(LOG_DEBUG,"IMAP delete of %d\n",x);
IMAP_DELETE(vms->curdir, x, vms->fn, vms); IMAP_DELETE(vms->curdir, x, vms->fn, vms);
} }
} }
#endif #endif
@ -6357,7 +6380,7 @@ static int vm_execmain(struct ast_channel *chan, void *data)
case '8': case '8':
if (vms.lastmsg > -1) { 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) { if (cmd == ERROR_LOCK_PATH) {
res = cmd; res = cmd;
goto out; goto out;
@ -6375,13 +6398,13 @@ static int vm_execmain(struct ast_channel *chan, void *data)
break; break;
} else if (cmd > 0) { } else if (cmd > 0) {
box = cmd = 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) { if (cmd == ERROR_LOCK_PATH) {
res = cmd; res = cmd;
goto out; goto out;
#ifdef IMAP_STORAGE #ifdef IMAP_STORAGE
} else if (cmd == 10) { } else if (cmd == 10) {
goto out; goto out;
#endif #endif
} else if (!cmd) { } else if (!cmd) {
vms.deleted[vms.curmsg] = 1; vms.deleted[vms.curmsg] = 1;
@ -6471,7 +6494,7 @@ out:
ast_log(LOG_DEBUG, "*** Checking if we can expunge, deleted set to %d, expungeonhangup set to %d\n",deleted,expungeonhangup); 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) { if (vmu && deleted == 1 && expungeonhangup == 1) {
#ifdef HAVE_IMAP_TK2006 #ifdef HAVE_IMAP_TK2006
if (LEVELUIDPLUS (vms.mailstream)) { if (LEVELUIDPLUS (vms.mailstream)) {
ast_log(LOG_DEBUG, "*** About to expunge messages using UID\n"); ast_log(LOG_DEBUG, "*** About to expunge messages using UID\n");
mail_expunge_full(vms.mailstream,NIL,EX_UID); mail_expunge_full(vms.mailstream,NIL,EX_UID);
} else } else
@ -6482,7 +6505,7 @@ out:
} }
} }
/* before we delete the state, we should copy pertainent info /* before we delete the state, we should copy pertainent info
back to the persistent model */ * back to the persistent model */
vmstate_delete(&vms); vmstate_delete(&vms);
#endif #endif
if (vmu) if (vmu)
@ -7463,7 +7486,7 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, s
} }
/* This will only work for new messages... */ /* 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 */ /* empty string means no valid header */
if (header_content == "" || header_content == NULL) { if (header_content == "" || header_content == NULL) {
ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]); ast_log (LOG_ERROR,"Could not fetch header for message number %ld\n",vms->msgArray[vms->curmsg]);
@ -7472,17 +7495,32 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, s
/* Get info from headers!! */ /* Get info from headers!! */
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Caller-ID-Num:"); 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]; cid = &cidS[0];
ast_log (LOG_DEBUG,"Caller id was set to: %s\n",cid); ast_log (LOG_DEBUG,"Caller id was set to: %s\n",cid);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Context:"); 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]; context = &contextS[0];
ast_log (LOG_DEBUG,"Context was set to: %s\n",context); ast_log (LOG_DEBUG,"Context was set to: %s\n",context);
temp = get_header_by_tag(header_content, "X-Asterisk-VM-Orig-time:"); 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]; origtime = &origtimeS[0];
ast_log (LOG_DEBUG,"Orig time was set to: %s\n",origtime); ast_log (LOG_DEBUG,"Orig time was set to: %s\n",origtime);
filename = "IMAP_STORAGE"; filename = "IMAP_STORAGE";
#else #else
@ -7845,7 +7883,7 @@ static int play_record_review(struct ast_channel *chan, char *playfile, char *re
} }
} }
} }
if (outsidecaller) if (outsidecaller)
ast_play_and_wait(chan, "vm-goodbye"); ast_play_and_wait(chan, "vm-goodbye");
if (cmd == 't') if (cmd == 't')
cmd = 0; cmd = 0;
@ -8131,26 +8169,26 @@ void mm_notify (MAILSTREAM * stream, char *string, long errflg)
void mm_list (MAILSTREAM * stream, int delim, char *mailbox, long attributes) void mm_list (MAILSTREAM * stream, int delim, char *mailbox, long attributes)
{ {
ast_log (LOG_NOTICE,"****** Entering callback\n"); ast_log (LOG_NOTICE,"****** Entering callback\n");
putchar (' '); putchar (' ');
if (delimiter) { if (delimiter) {
putchar (delimiter); putchar (delimiter);
delimiter = delim; delimiter = delim;
ast_log (LOG_NOTICE,"Delimiter set to %c\n",delim); ast_log (LOG_NOTICE,"Delimiter set to %c\n",delim);
} else { } else {
fputs ("NIL", stdout); fputs ("NIL", stdout);
} }
putchar (' '); putchar (' ');
fputs (mailbox, stdout); fputs (mailbox, stdout);
if (attributes & LATT_NOINFERIORS) if (attributes & LATT_NOINFERIORS)
fputs (", no inferiors", stdout); fputs (", no inferiors", stdout);
if (attributes & LATT_NOSELECT) if (attributes & LATT_NOSELECT)
fputs (", no select", stdout); fputs (", no select", stdout);
if (attributes & LATT_MARKED) if (attributes & LATT_MARKED)
fputs (", marked", stdout); fputs (", marked", stdout);
if (attributes & LATT_UNMARKED) if (attributes & LATT_UNMARKED)
fputs (", unmarked", stdout); fputs (", unmarked", stdout);
putchar ('\n'); putchar ('\n');
} }
@ -8342,32 +8380,32 @@ static char * get_user_by_mailbox(char *mailbox)
} }
static struct vm_state * get_vm_state_by_imapuser(char *user, int interactive) static struct vm_state * get_vm_state_by_imapuser(char *user, int interactive)
{ {
struct vmstate *vlist = NULL; struct vmstate *vlist = NULL;
vlist = vmstates; vlist = vmstates;
/* ast_log(LOG_DEBUG, "user set to:%s\n",user); */ /* ast_log(LOG_DEBUG, "user set to:%s\n",user); */
while (vlist) { while (vlist) {
if (vlist->vms != NULL) { if (vlist->vms != NULL) {
if (vlist->vms->imapuser != NULL) { if (vlist->vms->imapuser != NULL) {
/* ast_log(LOG_DEBUG, " comparing user %s to vmstate user %s\n",user,vlist->vms->imapuser); */ /* ast_log(LOG_DEBUG, " comparing user %s to vmstate user %s\n",user,vlist->vms->imapuser); */
if (strcmp(vlist->vms->imapuser,user) == 0) { if (strcmp(vlist->vms->imapuser,user) == 0) {
if (interactive == 2) { if (interactive == 2) {
/* ast_log(LOG_DEBUG, "Interactive set to ANY, current is: %d\n",vlist->vms->interactive); */ /* ast_log(LOG_DEBUG, "Interactive set to ANY, current is: %d\n",vlist->vms->interactive); */
return vlist->vms; return vlist->vms;
} else if (vlist->vms->interactive == interactive) { } else if (vlist->vms->interactive == interactive) {
/* ast_log(LOG_DEBUG, " Found it!\n"); */ /* ast_log(LOG_DEBUG, " Found it!\n"); */
return vlist->vms; return vlist->vms;
}
} }
} else {
ast_log(LOG_DEBUG, " error: imapuser is NULL for %s\n",user);
} }
} else { } 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); ast_log(LOG_DEBUG, " error: vms is NULL for %s\n",user);
} }
vlist = vlist->next; vlist = vlist->next;
} }
ast_log(LOG_DEBUG, "%s not found in vmstates\n",user); ast_log(LOG_DEBUG, "%s not found in vmstates\n",user);
return NULL; return NULL;
} }
@ -8484,19 +8522,18 @@ static void vmstate_delete(struct vm_state *vms)
static void set_update(MAILSTREAM * stream) static void set_update(MAILSTREAM * stream)
{ {
struct vm_state *vms; struct vm_state *vms;
char *mailbox; char *mailbox;
char *user; char *user;
mailbox = stream->mailbox; mailbox = stream->mailbox;
user = get_user_by_mailbox(mailbox); user = get_user_by_mailbox(mailbox);
vms = get_vm_state_by_imapuser(user, 0); vms = get_vm_state_by_imapuser(user, 0);
if (vms != NULL) { if (vms != NULL) {
ast_log (LOG_DEBUG, "User %s mailbox set for update.\n",user); ast_log (LOG_DEBUG, "User %s mailbox set for update.\n",user);
vms->updated = 2; /* set updated flag since mailbox changed */ vms->updated = 2; /* set updated flag since mailbox changed */
} else { } else {
ast_log (LOG_WARNING, "User %s mailbox not found for update.\n",user); ast_log (LOG_WARNING, "User %s mailbox not found for update.\n",user);
} }
} }
@ -8512,13 +8549,13 @@ static void init_vm_state(struct vm_state *vms)
static void check_msgArray(struct vm_state *vms) static void check_msgArray(struct vm_state *vms)
{ {
int x; int x;
ast_log (LOG_DEBUG, "Checking array\n"); ast_log (LOG_DEBUG, "Checking array\n");
for (x = 0; x<256; x++) { for (x = 0; x<256; x++) {
if (vms->msgArray[x]!=0) { if (vms->msgArray[x]!=0) {
ast_log (LOG_DEBUG, "Item %d set to %ld\n",x,vms->msgArray[x]); ast_log (LOG_DEBUG, "Item %d set to %ld\n",x,vms->msgArray[x]);
} }
} }
ast_log (LOG_DEBUG, "Check complete.\n"); ast_log (LOG_DEBUG, "Check complete.\n");
} }
static void copy_msgArray(struct vm_state *dst, struct vm_state *src) static void copy_msgArray(struct vm_state *dst, struct vm_state *src)
@ -8561,4 +8598,4 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, tdesc,
.load = load_module, .load = load_module,
.unload = unload_module, .unload = unload_module,
.reload = reload, .reload = reload,
); );