public static ASCIIArmoredMessage ParseMessage(string input)
        {
            ASCIIArmoredMessage message = new ASCIIArmoredMessage();
            string messageType = Regex.Match(input, @"(?<=-----BEGIN PGP )[A-Z ]+(?=-----)").Value;
            if (messageType.Equals("MESSAGE")) message.Type = ASCIIArmoredMessageType.Message;
            else if (messageType.Equals("PUBLIC KEY BLOCK")) message.Type = ASCIIArmoredMessageType.PublicKeyBlock;
            else if (messageType.Equals("PRIVATE KEY BLOCK")) message.Type = ASCIIArmoredMessageType.PrivateKeyBlock;
            else if (messageType.Equals("MESSAGE, PART X/Y")) message.Type = ASCIIArmoredMessageType.MessagePartXOutOfY;
            else if (messageType.Equals("MESSAGE, PART X")) message.Type = ASCIIArmoredMessageType.MessagePartX;
            else if (messageType.Equals("SIGNATURE")) message.Type = ASCIIArmoredMessageType.Signature;

            MatchCollection matches = Regex.Matches(input, @"\S+:(.|(\r?\n[\t ]))+");
            foreach (Match m in matches)
            {
                string name = m.Value.Substring(0, m.Value.IndexOf(':')).ToLower().Trim('\r', '\n'); ;
                string value = m.Value.Substring(m.Value.IndexOf(':') + 1).Trim('\r', '\n').TrimEnd(' ','\t');
                message.Headers.Add(name, value);
            }

            input = input.Trim('\r','\n');
            Match start = Regex.Match(input,@"\r\n[ \t]*\r\n");
            string packet = input.Substring(start.Index + start.Length);

            string checksum = Regex.Match(packet, @"(?<=\r\n=)[A-Za-z0-9+/=]{4}(?=\r\n-----END)").Value;
            message.CRCBase64 = checksum;

            packet = packet.Substring(0,Regex.Match(packet,@"\r\n[A-Za-z0-9+/=]{5}\r\n-----END").Index);

            //ActiveUp.Net.Mail.Logger.AddEntry(checksum);

            byte[] packetb = Convert.FromBase64String(packet);
            
            MemoryStream packetms = new MemoryStream(packetb);

            while (packetms.Position < packetms.Length)
            {
                Packet packetObj = GetNextPacket(ref packetms);
                message.Packets.Add(DispatchPacket(packetObj));
            }
            packetms.Close();

#if !PocketPC
            packetms.Dispose();
#endif

            return message;
        }
        public static ASCIIArmoredMessage ParseMessage(string input)
        {
            ASCIIArmoredMessage message = new ASCIIArmoredMessage();
            string messageType          = Regex.Match(input, @"(?<=-----BEGIN PGP )[A-Z ]+(?=-----)").Value;

            if (messageType.Equals("MESSAGE"))
            {
                message.Type = ASCIIArmoredMessageType.Message;
            }
            else if (messageType.Equals("PUBLIC KEY BLOCK"))
            {
                message.Type = ASCIIArmoredMessageType.PublicKeyBlock;
            }
            else if (messageType.Equals("PRIVATE KEY BLOCK"))
            {
                message.Type = ASCIIArmoredMessageType.PrivateKeyBlock;
            }
            else if (messageType.Equals("MESSAGE, PART X/Y"))
            {
                message.Type = ASCIIArmoredMessageType.MessagePartXOutOfY;
            }
            else if (messageType.Equals("MESSAGE, PART X"))
            {
                message.Type = ASCIIArmoredMessageType.MessagePartX;
            }
            else if (messageType.Equals("SIGNATURE"))
            {
                message.Type = ASCIIArmoredMessageType.Signature;
            }

            MatchCollection matches = Regex.Matches(input, @"\S+:(.|(\r?\n[\t ]))+");

            foreach (Match m in matches)
            {
                string name  = m.Value.Substring(0, m.Value.IndexOf(':')).ToLower().Trim('\r', '\n');;
                string value = m.Value.Substring(m.Value.IndexOf(':') + 1).Trim('\r', '\n').TrimEnd(' ', '\t');
                message.Headers.Add(name, value);
            }

            input = input.Trim('\r', '\n');
            Match  start  = Regex.Match(input, @"\r\n[ \t]*\r\n");
            string packet = input.Substring(start.Index + start.Length);

            string checksum = Regex.Match(packet, @"(?<=\r\n=)[A-Za-z0-9+/=]{4}(?=\r\n-----END)").Value;

            message.CRCBase64 = checksum;

            packet = packet.Substring(0, Regex.Match(packet, @"\r\n[A-Za-z0-9+/=]{5}\r\n-----END").Index);

            //ActiveUp.Net.Mail.Logger.AddEntry(checksum);

            byte[] packetb = Convert.FromBase64String(packet);

            MemoryStream packetms = new MemoryStream(packetb);

            while (packetms.Position < packetms.Length)
            {
                Packet packetObj = GetNextPacket(ref packetms);
                message.Packets.Add(DispatchPacket(packetObj));
            }
            packetms.Close();

#if !PocketPC
            packetms.Dispose();
#endif

            return(message);
        }