voicemsg voicemsg_tryparse(string l)
        {
            string boxname = substr(l, "<tr><td>", "</td>", true, false);

            if (boxname == null)
            {
                return(null);
            }
            string filename = substr(l,
                                     "box=" + boxname + "&message=",
                                     "\"",
                                     true,
                                     false);

            if (filename == null)
            {
                return(null);
            }
            string title = substr(l, "<td align=center nowrap>", "</td>",
                                  true, false);

            if (title == null)
            {
                return(null);
            }
            string timestamp = substr(l, "<td nowrap>", "</td>", true, false);

            if (timestamp == null)
            {
                return(null);
            }
            string duration = substr(l, "<td align=center>", "</td>",
                                     true, false);

            if (duration == null)
            {
                return(null);
            }
            string sizek = substr(l, duration + "</td><td>", "</td>", true, false);

            if (sizek == null)
            {
                return(null);
            }
            voicemsg result = new voicemsg();

            result.boxname   = boxname;
            result.filename  = filename;
            result.title     = title;
            result.timestamp = timestamp;
            result.duration  = duration;
            result.size      = sizek.Trim();
            return(result);
        }
        void download_voicemail(voicemsg m, string local_pathname)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string          url            = String.Format(voiceplayer_fmt, m.boxname, m.filename);
            HttpWebRequest  req            = getrequest(url);
            HttpWebResponse res            = (HttpWebResponse)req.GetResponse();
            int             nbytes         = 0;
            int             nreads         = 0;
            int             nbytesprogress = 0;

            if (res.StatusCode == HttpStatusCode.OK)
            {
                BinaryReader reader = new BinaryReader(res.GetResponseStream());
                using (Stream output_file_stream = new FileStream(local_pathname + ".tmp",
                                                                  FileMode.Create))
                {
                    const int chunkSize = 32000;
                    int       n;
                    byte[]    buf = new byte[chunkSize];
                    while ((n = reader.Read(buf, 0, chunkSize)) > 0)
                    {
                        nbytes += n;
                        nreads += 1;
                        output_file_stream.Write(buf, 0, n);
                        if (nbytes > (chunkSize + nbytesprogress))
                        {
                            if (stdout != null)
                            {
                                stdout.Write(".");
                            }
                            nbytesprogress = nbytes;
                        }
                    }
                }
                File.Move(local_pathname + ".tmp", local_pathname);
            }
            sw.Stop();
            msg(nreads + " reads to get " + nbytes + " in " + sw.Elapsed +
                " " +
                ((sw.ElapsedMilliseconds > 0)
           ? ((nbytes * 1000) / sw.ElapsedMilliseconds).ToString()
           : "0")
                +
                " bytes per second");
        }
        List <voicemsg> get_voicemsg_list()
        {
            List <voicemsg> result = new List <voicemsg>();
            string          l1     = get_voicemsg_list_content();

            /* The content is not good html, cannot be parsed using any common .NET
             * libraries for dealing with markup languages */
            string l2 = substr(l1, RECLSTART, RECLEND, true, true);

            string[] l3 = l2.Split('\n');
            foreach (string l in l3)
            {
                voicemsg t = voicemsg_tryparse(l);
                if (t != null)
                {
                    result.Add(t);
                }
            }
            return(result);
        }