
#include <getopt.h>
#include "ast_vbox.h"
#include <iostream>

using namespace std;

int main( int argc, char *argv[] )
{
  string p = "/var/spool/asterisk/voicemail/default";

  static struct option
    long_options[] =
    {
      {"directory", required_argument, NULL, 'd'},
      {NULL}
    };
  
  int c, option_index = 0;
  while ((c = getopt_long (argc, argv, "d:", long_options, &option_index)) != -1)
    {
      switch (c)
	{
	case 'd':
	  {
	    p = std::string( optarg );
	  }
	  break;
	}
    }

  astVoiceboxList vbl( p );

  list<astVoicebox> vblist = vbl.GetVoiceboxes();
  
  cout << "Voiceboxes in " << p << endl;
  for( list<astVoicebox>::iterator iter = vblist.begin();
       iter != vblist.end(); iter ++ )
    {
      cout << "Voicebox " << (*iter).GetName() << endl;

      list<astVoiceMessage> msgs = (*iter).GetMessages();
      for( list<astVoiceMessage>::iterator miter = msgs.begin();
	   miter != msgs.end(); miter ++ )
	{
	  cout << "   Message " << (*miter).GetCallerId() << "\t" << (*miter).GetTime() << "\t" << (*miter).GetDuration() << "\t" << (*miter).GetExtension() << "\t" << (*miter).GetSoundfile( "wav" ) << endl;
	}      
    }
}
