Show / Hide Table of Contents

Class MessageStoreSession

Class to deal with sessions for incoming/message store (i.e. IMAP) mail servers.
Instantiate this class with BeginReadAsync(SoMailFolder, CancellationToken).

Inheritance
object
MailSession<ISoIncomingMailInterface>
MessageStoreSession
Implements
IAsyncDisposable
Inherited Members
MailSession<ISoIncomingMailInterface>.LogoutAsync()
MailSession<ISoIncomingMailInterface>.DisposeAsync()
MailSession<ISoIncomingMailInterface>.Server
MailSession<ISoIncomingMailInterface>.UserName
MailSession<ISoIncomingMailInterface>.UseSSL
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
Namespace: SuperOffice.CRM.Mail
Assembly: SoDataBase.BusinessLogic.dll
Syntax
public sealed class MessageStoreSession : MailSession<ISoIncomingMailInterface>, IAsyncDisposable

Properties

CurrentFolder

Get the currently selected folder.

Declaration
public string CurrentFolder { get; }
Property Value
Type Description
string

Methods

CreateFolder(string, CancellationToken)

Create a new folder

Declaration
public Task CreateFolder(string folderName, CancellationToken cancellationToken)
Parameters
Type Name Description
string folderName

Full path and name of folder to create

CancellationToken cancellationToken
Returns
Type Description
Task

DeleteAsync(string, CancellationToken, params int[])

Deleted/move specified e-mails

Declaration
public Task DeleteAsync(string moveToFolder, CancellationToken cancellationToken, params int[] messageServerIds)
Parameters
Type Name Description
string moveToFolder
CancellationToken cancellationToken
int[] messageServerIds

Array of ids to target mail items

Returns
Type Description
Task

DeleteFolderAsync(string)

Delete a folder and all e-mails

Declaration
public Task DeleteFolderAsync(string folderName)
Parameters
Type Name Description
string folderName

Full path and name of folder to delete

Returns
Type Description
Task

EmptyFolderAsync(string, CancellationToken)

Delete all items in current folder

Declaration
public Task EmptyFolderAsync(string moveToFolder, CancellationToken cancellationToken)
Parameters
Type Name Description
string moveToFolder

If set, move deleted items to this folder

CancellationToken cancellationToken
Returns
Type Description
Task

GetAttachmentAsync(int, string, CancellationToken)

Retrieve an attachment from an e-mail

Declaration
public Task<MailAttachment> GetAttachmentAsync(int messageServerId, string attachmentId, CancellationToken cancellationToken)
Parameters
Type Name Description
int messageServerId

Unique id of the mail to get the attachment from

string attachmentId

Unique id of the attachment to get

CancellationToken cancellationToken
Returns
Type Description
Task<MailAttachment>

GetEMailAsStringAsync(string, CancellationToken)

Fetch a single e-mail optionally stripping attachments and deliver a stream to the raw MIME data(RFC 822)

Declaration
public Task<string> GetEMailAsStringAsync(string msgId, CancellationToken cancellationToken)
Parameters
Type Name Description
string msgId
CancellationToken cancellationToken
Returns
Type Description
Task<string>

Stream to a RFC 822 MIME representation of the e-mail

GetEMailAsync(int, bool, CancellationToken)

Fetch a single e-mail from the server

Declaration
public Task<MailItem> GetEMailAsync(int messageServerId, bool includeAttachmentStreams, CancellationToken cancellationToken)
Parameters
Type Name Description
int messageServerId

Unique server id for the item

bool includeAttachmentStreams

Should we include attachment streams(content).

CancellationToken cancellationToken
Returns
Type Description
Task<MailItem>

The e-mail

GetEMailStreamAsync(int, bool, bool, CancellationToken)

Fetch a single e-mail optionally stripping attachments and deliver a stream to the raw MIME data(RFC 822)

Declaration
public Task<Stream> GetEMailStreamAsync(int messageServerId, bool stripAttachments, bool sanitizeAttachments, CancellationToken cancellationToken)
Parameters
Type Name Description
int messageServerId

Unique server id for the item

bool stripAttachments

If true, get stream without attachments

bool sanitizeAttachments

If true, remove bad attachments.

CancellationToken cancellationToken
Returns
Type Description
Task<Stream>

Stream to a RFC 822 MIME representation of the e-mail

GetEnvelopeIdsAsync(string, CancellationToken)

Returns envelopes ids in the folder

Declaration
public Task<int[]> GetEnvelopeIdsAsync(string search, CancellationToken cancellationToken)
Parameters
Type Name Description
string search
CancellationToken cancellationToken
Returns
Type Description
Task<int[]>

GetEnvelopesAsync(MailSortCriterion, bool, CancellationToken)

Fetch all envelopes from current folder

Declaration
public Task<MailEnvelope[]> GetEnvelopesAsync(MailSortCriterion sortOrder, bool reverse, CancellationToken cancellationToken)
Parameters
Type Name Description
MailSortCriterion sortOrder

How return mails should be sorted

bool reverse

Reverse the sort order

CancellationToken cancellationToken
Returns
Type Description
Task<MailEnvelope[]>

All envelopes for the current folder

GetEnvelopesAsync(int, int, MailSortCriterion, bool, CancellationToken)

Fetch envelopes from the server

Declaration
public Task<MailEnvelope[]> GetEnvelopesAsync(int from, int to, MailSortCriterion sortOrder, bool reverse, CancellationToken cancellationToken)
Parameters
Type Name Description
int from

Based on the sortOrder retrieve e-mails from this index

int to

Based on the sortOrder retrieve e-mails till this index

MailSortCriterion sortOrder

How e-mails should be sorted

bool reverse

Reverse the sort order

CancellationToken cancellationToken
Returns
Type Description
Task<MailEnvelope[]>

Envelopes for the specified e-mails

GetEnvelopesAsync(int, int, MailSortCriterion, CancellationToken)

Fetch envelopes from the server based on message server ids.

Declaration
public Task<MailEnvelope[]> GetEnvelopesAsync(int from, int to, MailSortCriterion sortOrder, CancellationToken cancellationToken)
Parameters
Type Name Description
int from

from serverid

int to

To serverid

MailSortCriterion sortOrder

How e-mails should be sorted

CancellationToken cancellationToken
Returns
Type Description
Task<MailEnvelope[]>

Envelopes for the specified e-mails

GetEnvelopesAsync(int[], MailSortCriterion, bool, CancellationToken)

Fetch envelopes from the server based on message server ids.

Declaration
public Task<MailEnvelope[]> GetEnvelopesAsync(int[] messageIds, MailSortCriterion sortOrder, bool reverse, CancellationToken cancellationToken)
Parameters
Type Name Description
int[] messageIds

array of ids of messages to get

MailSortCriterion sortOrder

How e-mails should be sorted

bool reverse

Reverse the sort order

CancellationToken cancellationToken
Returns
Type Description
Task<MailEnvelope[]>

Envelopes for the specified e-mails

GetFolderExistAsync(string, CancellationToken)

Check if a specified folder exist on the server

Declaration
public Task<bool> GetFolderExistAsync(string folderName, CancellationToken cancellationToken)
Parameters
Type Name Description
string folderName

Full path and name of folder to verify existence of

CancellationToken cancellationToken
Returns
Type Description
Task<bool>

True if folder exists on the server. False is also returned if the connection to the mail server has been closed.

GetFolderInfoAsync(string[], CancellationToken)

returns folder information for the current list of folders

Declaration
public Task<SoMailFolderInfo[]> GetFolderInfoAsync(string[] folders, CancellationToken cancellationToken)
Parameters
Type Name Description
string[] folders
CancellationToken cancellationToken
Returns
Type Description
Task<SoMailFolderInfo[]>

GetFolderListAsync(CancellationToken)

Retrieve all subscribed folders for the account

Declaration
public Task<string[]> GetFolderListAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
Task<string[]>

Ex: { "Inbox", "Inbox/SubFolder", "Sent Items" }

GetFolderMailCountAsync(bool, CancellationToken)

Retrieve the number of e-mails in current folder

Declaration
public Task<int> GetFolderMailCountAsync(bool onlyUnread, CancellationToken cancellationToken)
Parameters
Type Name Description
bool onlyUnread

If true, only count unread e-mails

CancellationToken cancellationToken
Returns
Type Description
Task<int>

Number of e-mails

GetPartialEnvelopesAsync(int, int, MailSortCriterion, bool, string, CancellationToken)

Fetch envelopes but only populate values specified by the fields parameter Valid values are "Date From To Subject FLAGS RFC822.SIZE" The specified sortOrder will always include the field it is sorting on

Declaration
public Task<MailEnvelope[]> GetPartialEnvelopesAsync(int from, int to, MailSortCriterion sortOrder, bool revers, string fields, CancellationToken cancellationToken)
Parameters
Type Name Description
int from
int to
MailSortCriterion sortOrder
bool revers
string fields
CancellationToken cancellationToken
Returns
Type Description
Task<MailEnvelope[]>

GetRawFolderListAsync(bool, CancellationToken)

Retrieve all subscribed folders for the account

Declaration
public Task<string[]> GetRawFolderListAsync(bool includeItemCount, CancellationToken cancellationToken)
Parameters
Type Name Description
bool includeItemCount

Add unread and total number of items to the foldernames

CancellationToken cancellationToken
Returns
Type Description
Task<string[]>

List of folders. Each folder contains a delimeter character and the foldername, separated by the '§' character. Foldercounts are optionally added to each folder name. Ex: { "/§Inbox", "/§Inbox/SubFolder", "/§Sent Items" } { "/§Inbox,100,250", "/§Inbox/SubFolder,100,250", "/§Sent Items,100,100" }

MarkAsReadAsync(bool, CancellationToken, params int[])

Mark item as (un)read

Declaration
public Task MarkAsReadAsync(bool read, CancellationToken cancellationToken, params int[] messageServerIds)
Parameters
Type Name Description
bool read

If true, items are marked as read. If false, item is marked as unread

CancellationToken cancellationToken
int[] messageServerIds

Array of ids to target mail items

Returns
Type Description
Task

MoveToFolderAsync(string, CancellationToken, params int[])

Move item(s) from the current folder to targetFolder

Declaration
public Task MoveToFolderAsync(string targetFolder, CancellationToken cancellationToken, params int[] mesasgeServerIds)
Parameters
Type Name Description
string targetFolder

Name of folder to move items to

CancellationToken cancellationToken
int[] mesasgeServerIds

Array of ids to mail items

Returns
Type Description
Task

RenameFolderAsync(string, string, CancellationToken)

Rename an existing folder

Declaration
public Task RenameFolderAsync(string oldName, string newName, CancellationToken cancellationToken)
Parameters
Type Name Description
string oldName

Old name of the folder

string newName

New name of the folder

CancellationToken cancellationToken
Returns
Type Description
Task

SaveEMailAsync(MailItem, CancellationToken)

Save an e-mail back to the server

Declaration
public Task<MailItem> SaveEMailAsync(MailItem item, CancellationToken cancellationToken)
Parameters
Type Name Description
MailItem item

The e-mail item to save

CancellationToken cancellationToken
Returns
Type Description
Task<MailItem>

The saved e-mail

SaveEMailsAsync(MailItem[], CancellationToken)

Save a set of e-mails to the server

Declaration
public Task SaveEMailsAsync(MailItem[] items, CancellationToken cancellationToken)
Parameters
Type Name Description
MailItem[] items

The e-mails to save

CancellationToken cancellationToken
Returns
Type Description
Task

SelectFolderAsync(SoMailFolder, bool, CancellationToken)

Set an active folder

Declaration
public Task<bool> SelectFolderAsync(SoMailFolder folder, bool readOnly, CancellationToken cancellationToken)
Parameters
Type Name Description
SoMailFolder folder

Folder to set active

bool readOnly

If true, the mailbox folder is selected for "read-only" access. No changes to the permanent state of the folder are permitted

CancellationToken cancellationToken
Returns
Type Description
Task<bool>

True if the folder was successfully set active

SelectFolderAsync(string, bool, CancellationToken)

Set an active folder

Declaration
public Task<bool> SelectFolderAsync(string folderName, bool readOnly, CancellationToken cancellationToken)
Parameters
Type Name Description
string folderName

Full path and name of folder to set active

bool readOnly

If true, the mailbox folder is selected for "read-only" access. No changes to the permanent state of the folder are permitted

CancellationToken cancellationToken
Returns
Type Description
Task<bool>

True if the folder was successfully set active

ServerLoginAsync(string, string, string, bool, CancellationToken)

Log on to the mail server

Declaration
protected override Task<ISoIncomingMailInterface> ServerLoginAsync(string server, string userName, string password, bool useSSL, CancellationToken cancellationToken)
Parameters
Type Name Description
string server

Name of mail server with optional port.

string userName

User name used to authenticate to the mail server

string password

Password used to authenticate to the mail server

bool useSSL

Use SSL

CancellationToken cancellationToken
Returns
Type Description
Task<ISoIncomingMailInterface>

Instance of interface to the mail plugin.

Overrides
MailSession<ISoIncomingMailInterface>.ServerLoginAsync(string, string, string, bool, CancellationToken)

ServerLoginAsync(string, string, string, CancellationToken)

Log on to the mail server

Declaration
protected override Task<ISoIncomingMailInterface> ServerLoginAsync(string server, string userName, string password, CancellationToken cancellationToken)
Parameters
Type Name Description
string server

Name of mail server with optional port.

string userName

User name used to authenticate to the mail server

string password

Password used to authenticate to the mail server

CancellationToken cancellationToken
Returns
Type Description
Task<ISoIncomingMailInterface>

Instance of interface to the mail plugin.

Overrides
MailSession<ISoIncomingMailInterface>.ServerLoginAsync(string, string, string, CancellationToken)

ServerLogoutAsync()

Log out from the mail server.

Declaration
protected override Task ServerLogoutAsync()
Returns
Type Description
Task
Overrides
MailSession<ISoIncomingMailInterface>.ServerLogoutAsync()

SetFlagsAsync(EMailFlags, CancellationToken, params int[])

Set specified flags on e-mail(s)

Declaration
public Task SetFlagsAsync(EMailFlags flags, CancellationToken cancellationToken, params int[] messageServerIds)
Parameters
Type Name Description
EMailFlags flags

Flags to set on e-mail item

CancellationToken cancellationToken
int[] messageServerIds

E-mails to set flags on

Returns
Type Description
Task

Implements

System.IAsyncDisposable

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top