[Nmailserver-commits] SF.net SVN: nmailserver: [138] NMail/trunk/NMail
Brought to you by:
dframpton-oss,
tmyroadctfig
|
From: <tmy...@us...> - 2007-02-10 03:56:20
|
Revision: 138
http://svn.sourceforge.net/nmailserver/?rev=138&view=rev
Author: tmyroadctfig
Date: 2007-02-09 19:56:19 -0800 (Fri, 09 Feb 2007)
Log Message:
-----------
Further work on email rendering and displaying attachments.
Modified Paths:
--------------
NMail/trunk/NMail/DataTypes/BodyStructure.cs
NMail/trunk/NMail.RemoteAccessService.Serializers/DataTypes/BodyStructureSerializer.cs
NMail/trunk/NMail.WebAccess/App_Code/AttachmentDataSource.cs
NMail/trunk/NMail.WebAccess/App_Code/Helper.cs
NMail/trunk/NMail.WebAccess/App_WebReferences/RemoteAccessService/RemoteAccessService.wsdl
NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx
NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx.cs
Modified: NMail/trunk/NMail/DataTypes/BodyStructure.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/BodyStructure.cs 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail/DataTypes/BodyStructure.cs 2007-02-10 03:56:19 UTC (rev 138)
@@ -45,6 +45,7 @@
}
this.bodyCharacterCount = bodyData.Length;
+ this.size = bodyPart.Size;
}
}
@@ -83,8 +84,17 @@
get { return bodyCharacterCount; }
set { bodyCharacterCount = value; }
}
-
+ private int size;
+
+ /// <summary>
+ /// The size of this part in bytes.
+ /// </summary>
+ public int Size {
+ get { return size; }
+ set { size = value; }
+ }
+
public override string ToString() {
if (this.Count > 0) {
StringBuilder data = new StringBuilder();
Modified: NMail/trunk/NMail.RemoteAccessService.Serializers/DataTypes/BodyStructureSerializer.cs
===================================================================
--- NMail/trunk/NMail.RemoteAccessService.Serializers/DataTypes/BodyStructureSerializer.cs 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.RemoteAccessService.Serializers/DataTypes/BodyStructureSerializer.cs 2007-02-10 03:56:19 UTC (rev 138)
@@ -17,6 +17,7 @@
public BodyStructureSerializer(BodyStructure bodyStructure) {
this.headers = new MessageHeadersSerializer(bodyStructure.Headers);
+ this.size = bodyStructure.Size;
foreach (BodyStructure child in bodyStructure) {
this.parts.Add(new BodyStructureSerializer(child));
@@ -30,6 +31,13 @@
set { headers = value; }
}
+ private int size;
+
+ public int Size {
+ get { return size; }
+ set { size = value; }
+ }
+
private List<BodyStructureSerializer> parts = new List<BodyStructureSerializer>();
public List<BodyStructureSerializer> Parts {
Modified: NMail/trunk/NMail.WebAccess/App_Code/AttachmentDataSource.cs
===================================================================
--- NMail/trunk/NMail.WebAccess/App_Code/AttachmentDataSource.cs 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.WebAccess/App_Code/AttachmentDataSource.cs 2007-02-10 03:56:19 UTC (rev 138)
@@ -36,16 +36,13 @@
/// </summary>
public static class AttachmentDataSource
{
- public static List<AttachmentDetails> GetAttachmentDetails(Message message)
+ public static List<AttachmentDetails> GetAttachmentDetails(BodyStructure bodyStructure)
{
List<AttachmentDetails> result = new List<AttachmentDetails>();
- if (message.MultipartBody)
+ for (int i = 1; i < bodyStructure.Count; i++)
{
- for (int i = 0; i < message.MimeParts.Count; i++)
- {
- result.Add(new AttachmentDetails(message.MimeParts[i], i + 1));
- }
+ result.Add(new AttachmentDetails(bodyStructure[i], i + 1));
}
return result;
@@ -57,22 +54,22 @@
/// </summary>
public class AttachmentDetails
{
- public AttachmentDetails(IMessageBodyPart mimePart, int partNumber)
+ public AttachmentDetails(BodyStructure bodyStructure, int partNumber)
{
this.partNumber = partNumber;
// Get the name of the attachment
- this.name = MimeHelper.GetAttachmentName(mimePart.Headers);
+ this.name = MimeHelper.GetAttachmentName(bodyStructure.Headers);
if (name == null)
{
name = string.Format("Untitled: {0}", partNumber);
}
- this.size = mimePart.BodyData.Length;
+ this.size = bodyStructure.Size;
// Get the content type
Dictionary<string, string> parameters;
- this.contentType = MimeHelper.GetContentType(mimePart.Headers, out this.contentSubType, out parameters);
+ this.contentType = MimeHelper.GetContentType(bodyStructure.Headers, out this.contentSubType, out parameters);
}
private int partNumber;
Modified: NMail/trunk/NMail.WebAccess/App_Code/Helper.cs
===================================================================
--- NMail/trunk/NMail.WebAccess/App_Code/Helper.cs 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.WebAccess/App_Code/Helper.cs 2007-02-10 03:56:19 UTC (rev 138)
@@ -93,5 +93,10 @@
return s;
}
}
+
+ public string GetImageUrlForContentType(MimeContentType contentType, string subType)
+ {
+
+ }
}
}
Modified: NMail/trunk/NMail.WebAccess/App_WebReferences/RemoteAccessService/RemoteAccessService.wsdl
===================================================================
--- NMail/trunk/NMail.WebAccess/App_WebReferences/RemoteAccessService/RemoteAccessService.wsdl 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.WebAccess/App_WebReferences/RemoteAccessService/RemoteAccessService.wsdl 2007-02-10 03:56:19 UTC (rev 138)
@@ -190,6 +190,7 @@
<s:complexType name="BodyStructureSerializer">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Headers" type="tns:MessageHeadersSerializer" />
+ <s:element minOccurs="1" maxOccurs="1" name="Size" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="Parts" type="tns:ArrayOfBodyStructureSerializer" />
</s:sequence>
</s:complexType>
Modified: NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx
===================================================================
--- NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx 2007-02-10 03:56:19 UTC (rev 138)
@@ -31,15 +31,19 @@
<br />
<!-- The attachments -->
- <asp:Repeater ID="AttachmentsRepeater" runat="server">
- <ItemTemplate>
- <asp:LinkButton ID="AttachmentDownloadButton" runat="server">
- <asp:Image ID="AttachmentImage" runat="server" />
- <asp:Label ID="AttachmentNameLbl" runat="server" />
- <asp:Label ID="SizeLbl" runat="server" />
- </asp:LinkButton>
- </ItemTemplate>
- </asp:Repeater>
+ <table>
+ <asp:Repeater ID="AttachmentsRepeater" runat="server">
+ <ItemTemplate>
+ <tr><td>
+ <asp:LinkButton ID="AttachmentDownloadButton" runat="server">
+ <asp:Image ID="AttachmentImage" runat="server" />
+ <asp:Label ID="AttachmentNameLbl" runat="server" />
+ <asp:Label ID="SizeLbl" runat="server" />
+ </asp:LinkButton>
+ </td></tr>
+ </ItemTemplate>
+ </asp:Repeater>
+ </table>
</div>
</form>
</body>
Modified: NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx.cs
===================================================================
--- NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx.cs 2007-02-06 11:59:57 UTC (rev 137)
+++ NMail/trunk/NMail.WebAccess/Controls/Mail/MessageBody.aspx.cs 2007-02-10 03:56:19 UTC (rev 138)
@@ -59,17 +59,9 @@
get { return folderId; }
}
- private Message message;
+ private BodyStructure bodyStructure;
/// <summary>
- /// The message displayed in this form.
- /// </summary>
- public Message Message
- {
- get { return message; }
- }
-
- /// <summary>
/// Extracts the message and folder Ids from the query string.
/// </summary>
protected void ExtractQueryStringParams()
@@ -91,43 +83,47 @@
/// Examines the body structure to determine which MIME part to display as the
/// message body.
/// </summary>
- /// <param name="bodyStructure">The structure of the message.</param>
- /// <param name="partNumber">The part number to display.</param>
/// <param name="html">True if the part is a HTML part.</param>
- protected void FindMimePartToDisplay(BodyStructure bodyStructure, out int partNumber, out bool html)
+ /// <returns>The body part to display.</returns>
+ protected string FindMimePartToDisplay(Message firstMimePart, out bool html)
{
- if (bodyStructure.Count == 0)
+ // Get the content type
+ Dictionary<string, string> parameters;
+ string subType;
+ MimeContentType contentType;
+ contentType = MimeHelper.GetContentType(firstMimePart.Headers, out subType, out parameters);
+
+ if (contentType == MimeContentType.Text)
{
- // Simple message body, only one part to the message
- partNumber = 1;
- html = false;
+ html = (subType == "html");
+ return firstMimePart.BodyData.ToString();
}
- else
+ else if (contentType == MimeContentType.Multipart && subType == "alternative")
{
- partNumber = 1;
html = false;
+ string result = string.Empty;
- // Search for the best part
- for (int i = 0; i < bodyStructure.Count; i++)
+ for (int i = 0; i < firstMimePart.MimeParts.Count; i++)
{
- Dictionary<string, string> parameters;
- string subType;
- MimeContentType contentType = MimeHelper.GetContentType(bodyStructure[i].Headers, out subType, out parameters);
+ IMessageBodyPart part = firstMimePart.MimeParts[i];
+ contentType = MimeHelper.GetContentType(part.Headers, out subType, out parameters);
if (contentType == MimeContentType.Text)
{
- // We'll take the first text part we find unless something better appears
- partNumber = i + 1;
+ result = part.BodyData.ToString();
+ html = (subType == "html");
+ }
- if (subType == "html")
- {
- // We'll display the first HTML part we find
- html = true;
- break;
- }
+ if (html)
+ {
+ break;
}
}
}
+
+ // Nothing we understand...
+ html = false;
+ return string.Empty;
}
protected void Page_Init(object sender, EventArgs e)
@@ -150,32 +146,32 @@
return;
}
+
// Get our session variables
string authToken = (string)Session["AuthToken"];
RemoteAccessService.RemoteAccessService ras = (RemoteAccessService.RemoteAccessService)Session["RAS"];
// Get the body structure
- BodyStructureSerializer bs = ras.GetMessageStructure(authToken, messageId, folderId);
- BodyStructure bodyStructure = Helper.GetBodyStructure(bs);
+ BodyStructureSerializer bs = ras.GetMessageStructure(authToken, this.messageId, this.folderId);
+ this.bodyStructure = Helper.GetBodyStructure(bs);
+ // Get the first MIME part
+ string base64Body = ras.GetMessageMimePart(authToken, 1, messageId, folderId);
+ ByteString bodyData = new ByteString(Convert.FromBase64String(base64Body), Encoding.UTF8);
+ Message firstMimePart = new Message(bodyData);
+
// Find which part to display
- int bodyPartNumber;
bool htmlBody;
- FindMimePartToDisplay(bodyStructure, out bodyPartNumber, out htmlBody);
+ string messageBody = FindMimePartToDisplay(firstMimePart, out htmlBody);
- // Get the part to display
- string base64Body = ras.GetMessageMimePart(authToken, bodyPartNumber, messageId, folderId);
- ByteString bodyData = new ByteString(Convert.FromBase64String(base64Body), Encoding.UTF8);
- this.message = new Message(bodyData);
-
// Ensure all nasty stuff is escaped
if (htmlBody)
{
- this.MessageBody.Text = HtmlEscaper.EscapeScriptsAndImages(this.message.Data.ToString());
+ this.MessageBody.Text = HtmlEscaper.EscapeScriptsAndImages(messageBody);
}
else
{
- this.MessageBody.Text = HtmlEscaper.EscapeAll(this.message.Data.ToString());
+ this.MessageBody.Text = HtmlEscaper.EscapeAll(messageBody);
}
this.AttachmentsRepeater.ItemDataBound += new RepeaterItemEventHandler(AttachmentsRepeater_ItemDataBound);
@@ -193,7 +189,8 @@
void attachmentDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
- e.InputParameters.Add("message", this.message);
+
+ e.InputParameters.Add("bodyStructure", this.bodyStructure);
}
void AttachmentsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|