--- app_dial.bak 2009-03-19 16:33:19.000000000 -0400 +++ app_dial.c 2009-05-09 18:33:12.736530769 -0400 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */ @@ -61,6 +62,7 @@ #include "asterisk/stringfields.h" #include "asterisk/global_datastores.h" #include "asterisk/dsp.h" +#include "asterisk/mod_format.h" static char *app = "Dial"; @@ -186,11 +188,11 @@ " will cause the phone to ring back immediately. With a 2 specified,\n" " when the \"operator\" flashes the trunk, it will ring their phone\n" " back.\n" -" p - This option enables screening mode. This is basically Privacy mode\n" -" without memory.\n" -" P([x]) - Enable privacy mode. Use 'x' as the family/key in the database if\n" -" it is provided. The current extension is used if a database\n" -" family/key is not specified.\n" +" p - This option enables screening mode for every call.\n" +" P([x]) - Enable privacy mode based on caller ID. For a first time caller,\n" +" the called party is given a choice for future actions for that\n" +" caller. Use 'x' as the family/key in the database if it is provided.\n" +" The current extension is used if a database family/key is not specified.\n" " r - Indicate ringing to the calling party. Pass no audio to the calling\n" " party until the called channel has answered.\n" " S(x) - Hang up the call after 'x' seconds *after* the called party has\n" @@ -1234,7 +1236,25 @@ } snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid); - if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) { + /* See if the recorded introduction file already exists. + If we don't want introductions to persist, get rid of any from a prior incompleted call + because it could be a different person calling from the same office. + However, if the dial plan allows trying additional extensions, don't ask more than once in the same call. + We determine this by checking the file time against the starting time of the call. */ + res = -1; + if (ast_openstream(chan, pa->privintro, NULL)) { + struct stat introstat; + res = 1; + fstat(fileno(chan->stream->f), &introstat); + ast_closestream(chan->stream); + chan->stream = NULL; + if (ast_test_flag64(opts, OPT_SCREEN_NOINTRO) && chan->cdr && introstat.st_mtime <= chan->cdr->start.tv_sec) { + ast_filedelete(pa->privintro, NULL); + res = -1; + } + } + + if (res > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) { /* the DELUX version of this code would allow this caller the option to hear and retape their previously recorded intro. */