Is it possible to convert a Gmail API Message into an OpenPop Mime Message?
Currently, I have:
List<Message> messagesList = new List<Message>();
List<string> rawMessagesList = new List<string>();
foreach(Message m in messages)
{
Message m2 = service.Users.Messages.Get("me", m.Id).Execute();
string m3 = service.Users.Messages.Get("me", m.Id).Execute().Raw;
messagesList.Add(m2);
rawMessagesList.Add(m3);
}
string rMessage = rawMessagesList[0];
byte[] byteMessage = Encoding.ASCII.GetBytes(rMessage);
OpenPop.Mime.Message openPopMessage = new OpenPop.Mime.Message(byteMessage);
string newStringMessage = FindPlainTextInMessage(openPopMessage);
Console.Read();
Unfortunately, all it returns is nothing, because the raw request returns as null. Is there a scope requirement, or some other reason why gmail is not returning the raw message?
To obtain the Raw string, you need to specify the Raw format in your GetRequest.
At this point, rawString is a base64url encoded string. You have to convert it to a normal string before encoding to bytes (see http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-08#appendix-C):
You can then use the result of Base64UrlDecode to create the OpenPop MIME message.