/// <summary> /// Gets a specific message given an id, returned as a SimpleMessage /// </summary> /// <returns> /// The message converted to a SimpleMessage object /// </returns> private static SimpleMessage GetMessageById(string id) { log.Debug("Retrieving message with id: " + id); UsersResource.MessagesResource.GetRequest r = service.Users.Messages.Get("me", id); Message msg; try { msg = r.Execute(); } catch (Exception e) { log.Error("Error retrieving message with id: " + id, e); return null; } SimpleMessage simple = new SimpleMessage(); foreach (var headers in msg.Payload.Headers) { if (headers.Name.Equals("Subject")) simple.Subject = headers.Value; if (headers.Name.Equals("From")) simple.From = headers.Value; } if (msg.Payload.Body != null && msg.Payload.Body.Data != null) { string strData = msg.Payload.Body.Data.Replace('_', '/').Replace('-', '+'); byte[] data = Convert.FromBase64String(strData); string decodedstring = Encoding.UTF8.GetString(data); simple.Body = decodedstring; } else { foreach (var part in msg.Payload.Parts) { if (part.Body.Data != null && part.MimeType.Equals("text/plain")) { string strData = part.Body.Data.Replace('_', '/').Replace('-', '+'); byte[] data = Convert.FromBase64String(strData); string decodedstring = Encoding.UTF8.GetString(data); simple.Body = decodedstring; } } } simple.Message = msg; return simple; }
private static void EnqueueMessage(string to, string subject, string body) { if (to.Contains(Program.UnitTestAddress)) return; SimpleMessage outgoing = new SimpleMessage(); outgoing.To = to; outgoing.Subject = subject; outgoing.Body = body; outgoing.SendAttempts = 0; outgoingQueue.Enqueue(outgoing); }