PowerTCP Mail for .NET
BeginGetPart Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > ImapMessage Class : BeginGetPart Method




part
The part of the message to retrieve.
peek
Determines whether or not to mark the message as Seen when retrieving the part.
state
User state information.
Begins to asynchronously get a single part of the message.

Syntax

Visual Basic (Declaration) 
Public Function BeginGetPart( _
   ByVal part As Stream, _
   ByVal peek As Boolean, _
   ByVal state As Object _
) As IAsyncResult
Visual Basic (Usage)Copy Code
Dim instance As ImapMessage
Dim part As Stream
Dim peek As Boolean
Dim state As Object
Dim value As IAsyncResult
 
value = instance.BeginGetPart(part, peek, state)
C# 
public IAsyncResult BeginGetPart( 
   Stream part,
   bool peek,
   object state
)
Managed Extensions for C++ 
public: IAsyncResult* BeginGetPart( 
   Stream* part,
   bool peek,
   Object* state
) 
C++/CLI 
public:
IAsyncResult^ BeginGetPart( 
   Stream^ part,
   bool peek,
   Object^ state
) 

Parameters

part
The part of the message to retrieve.
peek
Determines whether or not to mark the message as Seen when retrieving the part.
state
User state information.

Return Value

An IAsyncResult that represents the asynchronous operation, which could still be pending.

Exceptions

ExceptionDescription
System.InvalidOperationExceptionBeginXXX method used without providing an EndXXX event handler.
Dart.PowerTCP.Mail.ProtocolExceptionBad IMAP protocol response received from server.
System.Net.Sockets.SocketExceptionThe requested address is not valid in its context.

Example

The following example demonstrates asynchronously retrieving a part of a message.
Visual BasicCopy Code
Private Sub AsynchronousGetPartTest()
   ' Login 
   Imap1.Login(Server, User, Pass)

   ' Retrieve message outlines for INBOX.
   Imap1.CurrentMailbox.Get(Imap1.CurrentMailbox.Messages(0), Imap1.CurrentMailbox.Messages(Imap1.CurrentMailbox.Messages.Count - 1), ImapMessageSections.BodyStructure Or ImapMessageSections.Envelope)

   ' Find the first message with an attachment
   Dim Attach As MimeAttachmentStream
   Dim AttachMessage As ImapMessage
   Dim Msg As ImapMessage
   For Each Msg In Imap1.CurrentMailbox.Messages	
      If (Msg.Message.Attachments.Count > 0) Then
         Attach = Msg.Message.Attachments(0)
         AttachMessage = Msg
         Exit For
       End If
   Next
   
   ' Get the attachment. When complete the Imap.EndGetPart event will be raised
   AttachMessage.BeginGetPart(Attach, Nothing)
End Sub

Private Sub Imap1_EndGetPart(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.MessagePartEventArgs) Handles Imap1.EndGetPart
   If e.Exception Is Nothing Then
      Debug.WriteLine("Part of message: " + e.Message.Id + " retrieved")
      Debug.WriteLine("Part Size = " & e.Part.Length)
   End If
End Sub
C#Copy Code
private void AsynchronousGetPartTest()
{
   // Login 
   imap1.Login(Server, User, Pass);

   // Retrieve message outlines for INBOX.
   imap1.CurrentMailbox.Get(imap1.CurrentMailbox.Messages[0], 
      imap1.CurrentMailbox.Messages[imap1.CurrentMailbox.Messages.Count - 1], 
      ImapMessageSections.BodyStructure | ImapMessageSections.Envelope);


   // Find the first message with an attachment
   MimeAttachmentStream attach = null;
   ImapMessage attachMessage = null;
   foreach(ImapMessage msg in imap1.CurrentMailbox.Messages)
   {
      if(msg.Message.Attachments.Count > 0)
      {
         // Save a reference to the attachment and message and break from the loop
         attach = (MimeAttachmentStream)msg.Message.Attachments[0];
         attachMessage = msg;
         break;
      }
   }
   
   // Get the attachment. When complete the Imap.EndGetPart event will be raised
   attachMessage.BeginGetPart(attach, null);
}

private void imap1_EndGetPart(object sender, Dart.PowerTCP.Mail.MessagePartEventArgs e)
{
   if(e.Exception == null)
   {
      Debug.WriteLine("Part of message: " + e.Message.Id + " retrieved");
      Debug.WriteLine("Part Size = " + e.Part.Length);
   }
}

Remarks

The ImapMessage.BeginGetPart method begins to get a single part of the message. Upon completion, the Imap.EndGetPart event will be raised. part must be an object from the MessageStream.Parts collection of the message. The component retrieves only the portion of the message represented by part and populates the content for this object. This is useful for allowing developers to download an attachment associated with a message without downloading the message itself.

Typically, before using this method, developers will need to call ImapMessage.GetOutline or ImapMessage.BeginGetOutline, which creates a MessageStream object with Part objects (containing no data) representing the parts contained within the message. The developer can then pass the Part object they would like to retrieve into the ImapMessage.GetPart method.

peek indicates whether this operation should mark the message as seen; if peek is true, then the Seen flag will not be changed. If peek is false, the Seen flag will be set to true.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.