MailMessage renderer



Hey, guys.

I whipped up a simple MailMessage renderer (attached).  

Some things that I'll work on when I wake up:

* Make the date format function a little more robust.  As it stands, I'm
using C#'s built-in DateTime.Parse function.  I don't know if the
EvoMail backend will give me the date in the same format for non-US
locales or not.  Also, the outputted date format is terribly US-centric
(month/day).  This should probably take into account the locale and
output accordingly.

* Add support for the message flags.  The renderer could then show
whether the message is new, has been read, has been replied to, has been
deleted, has attachments, etc.

* Sort the messages by date (newest messages first).

I'm definitely open to suggestions and comments.  

You can also download the code from here:
  http://www.geocities.com/godbyk/MailMessageMatchRenderer.cs.txt

And a simple screenshot is here:
  http://www.geocities.com/godbyk/dashboard-mail-renderer.png

-- 
Kevin Godby <godbyk yahoo com>
//
// GNOME Dashboard
//
// MailMessageMatchRenderer.cs: Knows how to render MailMessage matches.
//
// Author:
//   Kevin Godby <godbyk yahoo com>
//
// FIXME: Add support for msg flags
// FIXME: Test with international locales (especially date format)
// FIXME: Implement smarter date display (more info as date is further back in time)
// FIXME: Sort by date, newest mail first

using System;
using System.Collections;

namespace Dashboard {

	class MailMessageMatchRenderer : MatchRenderer {

		public override void Startup ()
		{
			Type = "MailMessage";
		}

		public override string HTMLRenderMatches (ArrayList matches)
		{
			string html = "";

			html += "<u>Email Messages</u>";
			html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";

			foreach (Match m in matches)
				html += HTMLRenderSingleMailMessage (m);

			html += "</table>";
			html += "<br><br>";

			return html;
		}

		private string HTMLRenderSingleMailMessage (Match m)
		{
			string html;

			string maildate = Convert.ToString (m ["sentdate"]);
			string ParsedDate = ParseMailDate (maildate);

			html = String.Format (
					      "<tr>" +
					      "    <td><img src=\"{0}\"></td>" +
					      "    <td nowrap>{1}</td>" +
					      "    <td align=\"right\">{2}</td>" +
					      "</tr>" +
					      "<tr>" +
					      "    <td>&nbsp;</td>" +
					      "    <td colspan=\"2\"><font color=\"#666666\">{3}</font></td>" +
					      "</tr>",
					      m ["icon"],
					      m ["from"],
					      ParsedDate,
					      m ["subject"]
					      );

			/*
			Console.WriteLine ("---\nFrom: {0}\nDate: {1}\nSubject: {2}\nFlags: {3}\nParsed Date: {4}", 
					   m ["from"], m ["sentdate"], m ["subject"], 
					   m ["flags"], ParsedDate
					  );
			*/


			return html;
		}

		private string ParseMailDate (string maildate)
		{
			// I don't know if the date format returned by the EvoMail backend
			// is always the same or if it is dependent upon the locale.
			// Assuming en-US throughout.
			DateTime ParsedDate = DateTime.Parse (maildate);

			// FIXME: Not the best date format (esp. for int'l users)
			return ParsedDate.ToString ("ddd M/d");
		}
	}
}

Attachment: dashboard-mail-renderer.png
Description: PNG image



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]