[asterisk-commits] mmichelson: branch mmichelson/imap_consistency_trunk r134978 - /team/mmichels...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 31 16:54:39 CDT 2008
Author: mmichelson
Date: Thu Jul 31 16:54:39 2008
New Revision: 134978
URL: http://svn.digium.com/view/asterisk?view=rev&rev=134978
Log:
Did a visual cleanup of handling of the separate prepended
message when using IMAP. Thoroughly untested yet, though.
Testing to follow
Modified:
team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c
Modified: team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c?view=diff&rev=134978&r1=134977&r2=134978
==============================================================================
--- team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c (original)
+++ team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c Thu Jul 31 16:54:39 2008
@@ -149,11 +149,11 @@
static void vmstate_delete(struct vm_state *vms);
static void set_update(MAILSTREAM * stream);
static void init_vm_state(struct vm_state *vms);
-static int save_body(BODY *body, struct vm_state *vms, char *section, char *format);
+static int save_body(BODY *body, struct vm_state *vms, char *section, char *format, int is_intro);
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, char *introfile, const char *flag);
+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, const char *flag);
static void update_messages_by_imapuser(const char *user, unsigned long number);
static int imap_remove_file (char *dir, int msgnum);
@@ -435,6 +435,7 @@
int vmArrayIndex;
char imapuser[80]; /*!< IMAP server login */
int interactive;
+ char introfn[PATH_MAX]; /*!< Name of prepended file */
unsigned int quota_limit;
unsigned int quota_usage;
struct vm_state *persist_vms;
@@ -446,7 +447,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,j,k) 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))
@@ -454,7 +455,7 @@
#else
#ifdef IMAP_STORAGE
#define DISPOSE(a,b) (imap_remove_file(a,b))
-#define STORE(a,b,c,d,e,f,g,h,i,j,k) (imap_store_file(a,b,c,d,e,f,g,h,i,j,k))
+#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 RETRIEVE(a,b,c,d) imap_retrieve_file(a,b,c,d)
#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));
@@ -463,7 +464,7 @@
#else
#define RETRIEVE(a,b,c,d)
#define DISPOSE(a,b)
-#define STORE(a,b,c,d,e,f,g,h,i,j,k)
+#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_plain_file(g,h));
@@ -1381,6 +1382,9 @@
return -1;
}
+ /* Greetings will never have a prepended message */
+ *vms_p->introfn = '\0';
+
ret = init_mailstream(vms_p, GREETINGS_FOLDER);
if (!vms_p->mailstream) {
ast_log(AST_LOG_ERROR, "IMAP mailstream is NULL\n");
@@ -1401,7 +1405,7 @@
if (!strcmp(filename, file)) {
ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
vms_p->msgArray[vms_p->curmsg] = i + 1;
- save_body(body, vms_p, "2", attachment);
+ save_body(body, vms_p, "2", attachment, 0);
return 0;
}
}
@@ -1451,6 +1455,7 @@
}
make_file(vms->fn, sizeof(vms->fn), dir, msgnum);
+ snprintf(vms->introfn, sizeof(vms->introfn), "%sintro", vms->fn);
/* Don't try to retrieve a message from IMAP if it already is on the file system */
if (ast_fileexists(vms->fn, NULL, NULL) > 0) {
@@ -1495,7 +1500,14 @@
goto exit;
}
- save_body(body, vms, "2", attachedfilefmt);
+ save_body(body, vms, "2", attachedfilefmt, 0);
+ /* A non-zero return here means that there is no prepended
+ * message saved here. We need to null the vms->introfn so
+ * that nothing attempts to play a nonexistent file later
+ */
+ if (save_body(body, vms, "3", attachedfilefmt, 1)) {
+ *vms->introfn = '\0';
+ }
/* Get info from headers!! */
snprintf(text_file, sizeof(text_file), "%s.%s", vms->fn, "txt");
@@ -1691,11 +1703,10 @@
return 0;
}
-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 *introfile, const char *flag)
+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, const char *flag)
{
char *myserveremail = serveremail;
char fn[PATH_MAX];
- char intro[PATH_MAX];
char mailbox[256];
char *stringp;
FILE *p=NULL;
@@ -1736,12 +1747,6 @@
tempcopy = 1;
}
- if (!ast_strlen_zero(introfile)) {
- snprintf(intro, sizeof(intro), "%s/msgintro%04d", dir, msgnum);
- } else {
- intro[0] = '\0';
- }
-
if (!strcmp(fmt, "wav49"))
fmt = "WAV";
ast_debug(3, "Storing file '%s', format '%s'\n", fn, fmt);
@@ -1763,7 +1768,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, intro, fmt, duration, 1, chan, NULL, 1, flag);
+ 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, vms->introfn, fmt, duration, 1, chan, NULL, 1, flag);
/* read mail file to memory */
len = ftell(p);
rewind(p);
@@ -2578,10 +2583,11 @@
ast_mutex_init(&vms->lock);
}
-static int save_body(BODY *body, struct vm_state *vms, char *section, char *format)
+static int save_body(BODY *body, struct vm_state *vms, char *section, char *format, int is_intro)
{
char *body_content;
char *body_decoded;
+ char *fn = is_intro ? vms->introfn : vms->fn;
unsigned long len;
unsigned long newlen;
char filename[256];
@@ -2591,7 +2597,7 @@
body_content = mail_fetchbody(vms->mailstream, vms->msgArray[vms->curmsg], section, &len);
if (body_content != NIL) {
- snprintf(filename, sizeof(filename), "%s.%s", vms->fn, format);
+ snprintf(filename, sizeof(filename), "%s.%s", fn, format);
/* ast_debug(1,body_content); */
body_decoded = rfc822_base64((unsigned char *)body_content, len, &newlen);
/* If the body of the file is empty, return an error */
@@ -4996,7 +5002,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, NULL, flag);
+ STORE(dir, vmu->mailbox, vmu->context, msgnum, chan, vmu, fmt, duration, vms, flag);
}
/* Are there to be more recipients of this message? */
@@ -5702,7 +5708,7 @@
* \return zero on success, -1 on error.
*/
static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu, char *curdir, int curmsg, char *vmfmts,
- char *context, signed char record_gain, long *duration, struct vm_state *vms, char *introfile, char *flag)
+ char *context, signed char record_gain, long *duration, struct vm_state *vms, char *flag)
{
#ifdef IMAP_STORAGE
int res;
@@ -5741,7 +5747,7 @@
/* Record new intro file */
res = ast_play_and_wait(chan, INTRO);
res = ast_play_and_wait(chan, "beep");
- res = play_record_review(chan, NULL, introfile, vmu->maxsecs, vmfmts, 1, vmu, (int *)duration, NULL, record_gain, vms, flag);
+ res = play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vmfmts, 1, vmu, (int *)duration, NULL, record_gain, vms, flag);
cmd = 't';
#else
@@ -5786,7 +5792,7 @@
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, prepend_duration, vms, NULL, NULL);
+ STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, prepend_duration, vms, NULL);
}
}
@@ -5794,7 +5800,7 @@
break;
case '2':
/* NULL out introfile so we know there is no intro! */
- introfile[0] = '\0';
+ *vms->introfn = '\0';
cmd = 't';
break;
case '*':
@@ -5962,7 +5968,6 @@
#ifdef IMAP_STORAGE
int todircount=0;
struct vm_state *dstvms;
- char tmpdir[PATH_MAX];
#endif
char username[70]="";
char fn[PATH_MAX]; /* for playback of name greeting */
@@ -6119,18 +6124,10 @@
leave_options.record_gain = record_gain;
cmd = leave_voicemail(chan, mailbox, &leave_options);
} else {
-
/* Forward VoiceMail */
long duration = 0;
char origmsgfile[PATH_MAX], msgfile[PATH_MAX];
struct vm_state vmstmp;
-#ifdef IMAP_STORAGE
- char *myserveremail = serveremail;
- /* create tempfile for forwarding intro */
- create_dirpath(tmpdir, sizeof(tmpdir), receiver->context, receiver->mailbox, "tmp");
- snprintf(tmptxtfile, sizeof(tmptxtfile), "%s/msgintro%04d", tmpdir, curmsg);
- ast_debug(5, "Creating temp file name %s...\n",tmptxtfile);
-#endif
memcpy(&vmstmp, vms, sizeof(vmstmp));
make_file(origmsgfile, sizeof(origmsgfile), dir, curmsg);
@@ -6143,11 +6140,12 @@
create_dirpath(vmstmp.curdir, sizeof(vmstmp.curdir), sender->context, vmstmp.username, "tmp");
make_file(msgfile, sizeof(msgfile), vmstmp.curdir, curmsg);
- cmd = vm_forwardoptions(chan, sender, vmstmp.curdir, curmsg, vmfmts, S_OR(context, "default"), record_gain, &duration, &vmstmp, tmptxtfile, urgent_str);
+ cmd = vm_forwardoptions(chan, sender, vmstmp.curdir, curmsg, vmfmts, S_OR(context, "default"), record_gain, &duration, &vmstmp, urgent_str);
if (!cmd) {
AST_LIST_TRAVERSE_SAFE_BEGIN(&extensions, vmtmp, list) {
#ifdef IMAP_STORAGE
int attach_user_voicemail;
+ char *myserveremail = serveremail;
/* get destination mailbox */
dstvms = get_vm_state_by_mailbox(vmtmp->mailbox,0);
@@ -6159,7 +6157,7 @@
if (!dstvms->mailstream) {
ast_log(AST_LOG_ERROR, "IMAP mailstream for %s is NULL\n", vmtmp->mailbox);
} else {
- STORE(vmstmp.curdir, vmtmp->mailbox, vmtmp->context, dstvms->curmsg, chan, vmtmp, fmt, duration, dstvms, tmptxtfile, urgent_str);
+ STORE(vmstmp.curdir, vmtmp->mailbox, vmtmp->context, dstvms->curmsg, chan, vmtmp, fmt, duration, dstvms, urgent_str);
run_externnotify(vmtmp->context, vmtmp->mailbox, urgent_str);
}
} else {
@@ -6169,8 +6167,7 @@
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, tmptxtfile, fmt, duration, attach_user_voicemail, chan, NULL, urgent_str);
-
+ sendmail(myserveremail, vmtmp, todircount, vmtmp->context, vmtmp->mailbox, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL), vms->fn, vms->introfn, fmt, duration, attach_user_voicemail, chan, NULL, urgent_str);
#else
copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir, urgent_str);
#endif
@@ -6192,9 +6189,7 @@
res = ast_play_and_wait(chan, "vm-saved"); */
/* If forwarded with intro, DON'T PLAY THIS MESSAGE AGAIN! */
- if (ast_strlen_zero(tmptxtfile)) { /* not a forwarded message with intro */
- res = ast_play_and_wait(chan, "vm-msgsaved");
- }
+ res = ast_play_and_wait(chan, "vm-msgsaved");
}
}
}
@@ -6536,7 +6531,14 @@
if (!res) {
make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg);
vms->heard[vms->curmsg] = 1;
- if ((res = wait_file(chan, vms, vms->fn)) < 0) {
+#ifdef IMAP_STORAGE
+ /*IMAP storage stores any prepended message from a forward
+ * as a separate file from the rest of the message
+ */
+ if (!ast_strlen_zero(vms->introfn));
+ res = wait_file(chan, vms, vms->introfn);
+#endif
+ if (res || (res = wait_file(chan, vms, vms->fn)) < 0) {
ast_log(AST_LOG_WARNING, "Playback of message %s failed\n", vms->fn);
res = 0;
}
@@ -10931,7 +10933,7 @@
if (!outsidecaller) {
/* Saves to IMAP server - but SHOULD save to filesystem ONLY if recording greetings! */
#ifndef IMAP_STORAGE
- STORE(recordfile, vmu->mailbox, vmu->context, -1, chan, vmu, fmt, *duration, vms, NULL, flag);
+ STORE(recordfile, vmu->mailbox, vmu->context, -1, chan, vmu, fmt, *duration, vms, flag);
DISPOSE(recordfile, -1);
#endif
}
More information about the asterisk-commits
mailing list