MailClient.Expunge Method


Pures the deleted emails in current selected folder on IMAP4 server.

[Visual Basic]
Public Sub Expunge( _
)
[C#]
public void Expunge(
);
[C++]
public: void Expunge(
);
[JScript]
public function Expunge(
);

Remarks

MailClient.Delete method only marks the email as deleted, only the MailClient.Quit method (POP3 and IMAP4) or MailClient.Expunge method(IMAP4 only) pures the deleted email from server. For POP3, deleted flag will lose if the connection is closed; FOR IMAP4, the deleted flag is permant even the connection is closed.

Example

[Visual Basic, C#, C++] The following example demonstrates how to delete and pure email with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.

[Visual Basic]
Imports EAGetMail

Public Sub PureMail( _
ByVal sServer As String, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal bSSLConnection As Boolean)
    Dim oClient As New MailClient("TryIt")
    
    Dim oServer As New MailServer(sServer, _
        sUserName, sPassword, bSSLConnection, _
        ServerAuthType.AuthLogin, ServerProtocol.Imap4)
    
    ' generates a log file
    ' oClient.LogFileName = "c:\pop.log"
    
    Try
        oClient.Connect(oServer)
        Dim infos() As MailInfo = oClient.GetMailInfos()
        Dim count As Integer = infos.Length
        
        For i As Integer = 0 To count - 1
            Dim info As MailInfo = infos(i)
            oClient.Delete(info)
        Next
        '
        ' Delete method just mark the email as deleted, 
        ' Expunge method pure the emails from server exactly.
        oClient.Expunge()
        oClient.Logout()

    Catch ep As MailServerException
        ''Message contains the information returned by mail server
        Console.WriteLine("Server Respond: {0}", ep.Message)
    Catch ep As System.Net.Sockets.SocketException
        Console.WriteLine("Socket Error: {0}", ep.Message)
    Catch ep As Exception
        Console.WriteLine("System Error: {0}", ep.Message)
    End Try
    
    ' show the conversation between server and client.
    Console.WriteLine( oClient.Conversation )
    oClient.Close()
End Sub

[C#]
using System;
using System.Collections;
using EAGetMail;

public void PureMail( 
    string sServer, 
    string sUserName,
    string sPassword,
    bool bSSLConnection)
{
    MailClient oClient = new MailClient("TryIt");
    
    MailServer oServer  = new MailServer(sServer, 
        sUserName, sPassword, bSSLConnection, 
        ServerAuthType.AuthLogin, ServerProtocol.Imap4);
    
    // generates a log file
    // oClient.LogFileName = "c:\\pop3.log";
    
    try
    {
        oClient.Connect(oServer);
        MailInfo [] infos = oClient.GetMailInfos();
        int count = infos.Length;

        for( int i = 0; i < count; i++ )
        {
            MailInfo info = infos[i];
            oClient.Delete(info);
        }
    
        // Delete method just mark the email as deleted, 
        // Expunge method pure the emails from server exactly.
        oClient.Expunge();
        oClient.Logout();
    }
    catch( MailServerException ep ) 
    {
        //Message contains the information returned by mail server
        Console.WriteLine("Server Respond: {0}", ep.Message);
    }
    catch( System.Net.Sockets.SocketException ep ) 
    {
        Console.WriteLine("Socket Error: {0}", ep.Message);
    }
    catch( Exception ep ) 
    {
        Console.WriteLine("System Error: {0}", ep.Message);
    }

    // show the conversation between server and client.
    Console.WriteLine( oClient.Conversation );
    oClient.Close();
}

[C++]
using namespace System;
using namespace System::Collections;
using namespace EAGetMail; 

Void PureMail( 
        String *sServer, 
        String *sUserName,
        String *sPassword,
        bool bSSLConnection)
{
    MailClient *oClient = new MailClient(S"TryIt");
    
    MailServer *oServer  = new MailServer(sServer, 
        sUserName, sPassword, bSSLConnection, 
        ServerAuthType::AuthLogin, ServerProtocol::Imap4);
    
    // generates a log file
    // oClient-> = S"c:\\pop.log";
    try
    {
        oClient->Connect(oServer);
        MailInfo *infos[]= oClient->GetMailInfos();
        int count = infos->Length;

        for( int i = 0; i < count; i++ )
        {
            MailInfo *info = infos[i];
            oClient->Delete(info);
        }
    
        // Delete method just mark the email as deleted, 
        // Expunge method pure the emails from server exactly.
        oClient->Expunge();
        oClient->Logout();
    }
    catch( MailServerException *ep ) 
    {
        //Message contains the information returned by mail server
        Console::WriteLine( S"Server Respond: {0}", ep->Message);
    }
    catch( System::Net::Sockets::SocketException *ep ) 
    {
        Console::WriteLine( S"Socket Error: {0}", ep->Message);
    }
    catch( Exception *ep ) 
    {
        Console::WriteLine( S"System Error: {0}", ep->Message);
    }
    
    // show the conversation between server and client.
    Console::WriteLine( oClient->Conversation );
    oClient->Close();
}