Re: [asterisk-users] Deleting voicemail by program

2023-10-11 Thread Mike Diehl
John, that is some serious script-fu!  I does exactly what I was going to do 
in perl.  However, my initial testing indicates that asterisk will renumber 
voicemail boxes to eliminate holes.  But I'm still testing.

Thanks again,

Mike.

On Tuesday, October 10, 2023 11:47:35 AM EDT John Harragin wrote:
> Here is something I wrote years ago. I expect you can adjust it for your
> needs
> 
> 
> 
> # cat remove_blank_vmail
> #!/bin/bash
> # remove_blank_vmail takes arguments as voicemail boxes and removes
> messages with audio files shorter then MINSIZE (in bytes)
> #--
> # Description:
> # Author: John Harragin Monroe-Woodbury CSD
> # Created at: Thu Nov  6 12:27:35 EST 2008
> #
> # Copyright: None. Modify and use however you like...
> #
> #--
> # Configure section:
> 
> BASEDIR=/var/spool/asterisk/voicemail/default/  # default
> context
> MINSIZE=12000   # 1.5
> seconds
> 
> #--subroutines:
> 
> ProcessDir () {
>  lastfile=""
>  delcnt=0
>  for file in $(ls -A ${msgdir}/msg*.txt 2>/dev/null); do   # the
> redirect supresses msg when dir empty
>if [ $(stat --format=%s ${file/.txt/.wav}) -lt ${MINSIZE} ]; then
>  rm ${file/.txt/.*}
>  let delcnt++
>fi
>lastfile=${file}
>  done
>  if [ $delcnt -gt 0 ]; then echo "$delcnt short messages deleted from
> ${msgdir}"; fi
>  partfilename=${lastfile/*\/msg/}  # get number
> from file name
>  highest=${partfilename/.txt/}
>  while [[ $highest = 0* ]]; do highest=${highest#0}; done  # bash does
> not like leading zeros
>  if [ ${#highest} -eq 0 ]; then highest=0; fi  # ...or
> blanks for math
>  realcount=0
>  for ((x=0;x<=${highest};x+=1)); do
>chkname=msg$(printf "%04d" $x)  # build name
> - pad with zeros...
>if [ -e ${msgdir}/${chkname}.txt ]; then
>  if [ $realcount -ne $x ];then
>newname=msg$(printf "%04d" $realcount)
>for idivfile in $(ls -A ${msgdir}/${chkname}.*); do
>  mv ${idivfile} ${msgdir}/${newname}.${idivfile/*\/*./}
>done
>  fi
>  let realcount++
>fi
>  done
> }
> 
> #--main:
> 
> for ext in "$@"; do
>  if [ -d ${BASEDIR}${ext} ];then
>for msgdir in $(ls -d ${BASEDIR}${ext}/*); do
>  ProcessDir ${msgdir}
>done
>  else
>echo "${BASEDIR}${ext} is not a valid directory"
>  fi
>  echo "Processed extension $ext"
> done
> 
> On Mon, Oct 9, 2023 at 3:06 PM Mike Diehl  wrote:
> > Hi all,
> > 
> > I need to be able to delete a voicemail message using a program.
> > 
> > Is is sufficient to simply delete the .wav and .txt files in the spool
> > directory?
> > Or do I need to also renumber the remaining files?
> > 
> > For example, let say a given mailbox has 20 messages in it and I want to
> > delete message number 5.  Can I just delete the 2 files and expect that
> > asterisk will renumber them?  Or do I need to?
> > 
> > Also, is the answer the same when I migrate to storing voicemails in a
> > database?
> > 
> > Thanks in advance.
> > 
> > Mike
> > 
> > 
> > 
> > --
> > _
> > -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> > 
> > Check out the new Asterisk community forum at:
> > https://community.asterisk.org/
> > 
> > New to Asterisk? Start here:
> >   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
> > 
> > asterisk-users mailing list
> > 
> > To UNSUBSCRIBE or update options visit:
> >http://lists.digium.com/mailman/listinfo/asterisk-users





-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Deleting voicemail by program

2023-10-10 Thread John Harragin
Here is something I wrote years ago. I expect you can adjust it for your
needs



# cat remove_blank_vmail
#!/bin/bash
# remove_blank_vmail takes arguments as voicemail boxes and removes
messages with audio files shorter then MINSIZE (in bytes)
#--
# Description:
# Author: John Harragin Monroe-Woodbury CSD
# Created at: Thu Nov  6 12:27:35 EST 2008
#
# Copyright: None. Modify and use however you like...
#
#--
# Configure section:

BASEDIR=/var/spool/asterisk/voicemail/default/  # default
context
MINSIZE=12000   # 1.5
seconds

#--subroutines:

ProcessDir () {
 lastfile=""
 delcnt=0
 for file in $(ls -A ${msgdir}/msg*.txt 2>/dev/null); do   # the
redirect supresses msg when dir empty
   if [ $(stat --format=%s ${file/.txt/.wav}) -lt ${MINSIZE} ]; then
 rm ${file/.txt/.*}
 let delcnt++
   fi
   lastfile=${file}
 done
 if [ $delcnt -gt 0 ]; then echo "$delcnt short messages deleted from
${msgdir}"; fi
 partfilename=${lastfile/*\/msg/}  # get number
from file name
 highest=${partfilename/.txt/}
 while [[ $highest = 0* ]]; do highest=${highest#0}; done  # bash does
not like leading zeros
 if [ ${#highest} -eq 0 ]; then highest=0; fi  # ...or
blanks for math
 realcount=0
 for ((x=0;x<=${highest};x+=1)); do
   chkname=msg$(printf "%04d" $x)  # build name
- pad with zeros...
   if [ -e ${msgdir}/${chkname}.txt ]; then
 if [ $realcount -ne $x ];then
   newname=msg$(printf "%04d" $realcount)
   for idivfile in $(ls -A ${msgdir}/${chkname}.*); do
 mv ${idivfile} ${msgdir}/${newname}.${idivfile/*\/*./}
   done
 fi
 let realcount++
   fi
 done
}

#--main:

for ext in "$@"; do
 if [ -d ${BASEDIR}${ext} ];then
   for msgdir in $(ls -d ${BASEDIR}${ext}/*); do
 ProcessDir ${msgdir}
   done
 else
   echo "${BASEDIR}${ext} is not a valid directory"
 fi
 echo "Processed extension $ext"
done




On Mon, Oct 9, 2023 at 3:06 PM Mike Diehl  wrote:

> Hi all,
>
> I need to be able to delete a voicemail message using a program.
>
> Is is sufficient to simply delete the .wav and .txt files in the spool
> directory?
> Or do I need to also renumber the remaining files?
>
> For example, let say a given mailbox has 20 messages in it and I want to
> delete message number 5.  Can I just delete the 2 files and expect that
> asterisk will renumber them?  Or do I need to?
>
> Also, is the answer the same when I migrate to storing voicemails in a
> database?
>
> Thanks in advance.
>
> Mike
>
>
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at:
> https://community.asterisk.org/
>
> New to Asterisk? Start here:
>   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Deleting voicemail by program

2023-10-09 Thread Antony Stone
On Monday 09 October 2023 at 21:05:55, Mike Diehl wrote:

> Hi all,
> 
> I need to be able to delete a voicemail message using a program.
> 
> Is is sufficient to simply delete the .wav and .txt files in the spool
> directory? Or do I need to also renumber the remaining files?

My approach in a situation like this would often be "try it and see".

Leave yourself three voicemail messages, remove the middle one simply by 
deleting the files, and see what Asterisk makes of what's left behind:

 - does it report three messages but only play two?

 - does it report either two or three messages but can only play the first?

 - does it report two messages and play them without problem?

 - does it report two messages and fail to play anything?

 - does it report no messages?

 - does it have a problem when a fourth message gets left?

None of the above behaviour is _necessarily_ transferrable to a future version 
of Asterisk, but at least it tells you what your current version does when you 
interfere with in this way..


Antony.

-- 
.evah I serutangis sseltniop tsom eht fo eno eb tsum sihT

   Please reply to the list;
 please *don't* CC me.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Deleting voicemail by program

2023-10-09 Thread Carlos Chavez
    The script included with Asterisk (messages-expire.pl) deletes 
older messages and then renumbers the rest of the messages.  I guess you 
need to do the same.


On 09/10/23 2:24 PM, Mike Diehl wrote:

Unfortunately, I'm using a version of asterisk that is old enough to not
benefit from this... 

Mike.

On Monday, October 9, 2023 3:15:45 PM EDT Michael Bradeen wrote:

Hi Mike,

New AMI actions were recently added to app_voicemail to let you remotely
manipulate a mailbox:
https://github.com/asterisk/asterisk/issues/181

Hope this helps.

BR,
-Mike

On Mon, Oct 9, 2023 at 1:06 PM Mike Diehl  wrote:

Hi all,

I need to be able to delete a voicemail message using a program.

Is is sufficient to simply delete the .wav and .txt files in the spool
directory?
Or do I need to also renumber the remaining files?

For example, let say a given mailbox has 20 messages in it and I want to
delete message number 5.  Can I just delete the 2 files and expect that
asterisk will renumber them?  Or do I need to?

Also, is the answer the same when I migrate to storing voicemails in a
database?

Thanks in advance.

Mike



--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at:
https://community.asterisk.org/

New to Asterisk? Start here:
   https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list

To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users






--
Telecomunicaciones Abiertas de México S.A. de C.V.
Carlos Chávez
+52 (55)8116-9161


--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
 https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Deleting voicemail by program

2023-10-09 Thread Mike Diehl
Unfortunately, I'm using a version of asterisk that is old enough to not 
benefit from this... 

Mike.

On Monday, October 9, 2023 3:15:45 PM EDT Michael Bradeen wrote:
> Hi Mike,
> 
> New AMI actions were recently added to app_voicemail to let you remotely
> manipulate a mailbox:
> https://github.com/asterisk/asterisk/issues/181
> 
> Hope this helps.
> 
> BR,
> -Mike
> 
> On Mon, Oct 9, 2023 at 1:06 PM Mike Diehl  wrote:
> > Hi all,
> > 
> > I need to be able to delete a voicemail message using a program.
> > 
> > Is is sufficient to simply delete the .wav and .txt files in the spool
> > directory?
> > Or do I need to also renumber the remaining files?
> > 
> > For example, let say a given mailbox has 20 messages in it and I want to
> > delete message number 5.  Can I just delete the 2 files and expect that
> > asterisk will renumber them?  Or do I need to?
> > 
> > Also, is the answer the same when I migrate to storing voicemails in a
> > database?
> > 
> > Thanks in advance.
> > 
> > Mike
> > 
> > 
> > 
> > --
> > _
> > -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> > 
> > Check out the new Asterisk community forum at:
> > https://community.asterisk.org/
> > 
> > New to Asterisk? Start here:
> >   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
> > 
> > asterisk-users mailing list
> > 
> > To UNSUBSCRIBE or update options visit:
> >http://lists.digium.com/mailman/listinfo/asterisk-users





-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Deleting voicemail by program

2023-10-09 Thread Michael Bradeen
Hi Mike,

New AMI actions were recently added to app_voicemail to let you remotely
manipulate a mailbox:
https://github.com/asterisk/asterisk/issues/181

Hope this helps.

BR,
-Mike


On Mon, Oct 9, 2023 at 1:06 PM Mike Diehl  wrote:

> Hi all,
>
> I need to be able to delete a voicemail message using a program.
>
> Is is sufficient to simply delete the .wav and .txt files in the spool
> directory?
> Or do I need to also renumber the remaining files?
>
> For example, let say a given mailbox has 20 messages in it and I want to
> delete message number 5.  Can I just delete the 2 files and expect that
> asterisk will renumber them?  Or do I need to?
>
> Also, is the answer the same when I migrate to storing voicemails in a
> database?
>
> Thanks in advance.
>
> Mike
>
>
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at:
> https://community.asterisk.org/
>
> New to Asterisk? Start here:
>   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] Deleting voicemail by program

2023-10-09 Thread Mike Diehl
Hi all,

I need to be able to delete a voicemail message using a program.  

Is is sufficient to simply delete the .wav and .txt files in the spool 
directory?  
Or do I need to also renumber the remaining files?

For example, let say a given mailbox has 20 messages in it and I want to 
delete message number 5.  Can I just delete the 2 files and expect that 
asterisk will renumber them?  Or do I need to?

Also, is the answer the same when I migrate to storing voicemails in a 
database?

Thanks in advance.

Mike



-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users