Text PreviewerGet Preview Text(Text Part) Method
Get a text preview of the text part.
Definition
Namespace: MimeKit.Text
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
A string representing a shortened preview of the original text.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static string GetPreviewText(
TextPart body
)Parameters
- body TextPart
- The text part.
Return Value
StringA string representing a shortened preview of the original text.
Remarks
Gets a text preview of the text part.
Example
C#
public static string GetPreviewText (MimeMessage message)
{
// TextPreviewer.GetPreviewText() picks the appropriate previewer (PlainTextPreviewer or
// HtmlTextPreviewer) based on the format of the text part and returns a short, single-line
// snippet of the text which is useful for displaying in a message list.
var body = message.BodyParts.OfType<TextPart> ().FirstOrDefault (x => !x.IsAttachment);
if (body == null)
return string.Empty;
if (body.IsHtml) {
// The previewers can also be used directly in order to customize the length.
var previewer = new HtmlTextPreviewer { MaximumPreviewLength = 100 };
return previewer.GetPreviewText (body.Text);
}
return TextPreviewer.GetPreviewText (body);
}
Exceptions
| ArgumentNullException | body is . |