Encode IMAP4 folder name with UTF-7.
[Syntax] C++: HRESULT EncodeIMAP4Folder( BSTR Folder, BSTR* pVal ) Visual Basic: EncodeIMAP4Folder( Folder As String ) As String C#: string EncodeIMAP4Folder( string Folder )
Parameters
Folder
Folder name to encode.
Return Value
This method returns the string encoded by UTF-7.
Remarks
Based on IMAP4 protocol, the folder(mailbox) name with NON-ASCII characters needs to be encoded by UTF-7. With execIMAP4Command method, every folder name should be encoded by EncodeIMAP4Folder at first; and the result of execIMAP4Command method should be decoded by DecodeIMAP4Folder as well.
For IMAP4Folder property, the user should not use EncodeIMAP4Folder or DecodeIMAP4Folder methods, ANPOP object will encode/decode it automatically.
Usage Example
[Visual Baisc]
Function IsGoodResponse(ByVal s As String, ByVal id As String) As Boolean
id = id & " OK"
If InStr(1, s, id, vbTextCompare) > 0 Then
IsGoodResponse = True
Else
IsGoodResponse = False
End If
End Function
Sub CreateFolder( imap4Server As String, imap4User As String, imap4Password As String, folder As String )
Dim oImap4 As ANPOPLib.POPMAIN
Set oImap4 = new ANPOPLib.POPMAIN 'Create object instance
oImap4.IMAP4Connection = 1
oImap4.ServerPort = 143
nRet = oImap4.Connect( imap4Server, imap4User, imap4Password ) 'Connect IMAP4 server
If nRet <> 0 Then
MsgBox "error with connecting server"
goto ErrorHandler
End If
Dim cmdId, response, command
cmdId = "A001"
command = cmdId & " CREATE """ & oImap4.EncodeIMAP4Folder(folder) & """" & Chr(13) & Chr(10)
response = Trim(oImap4.execIMAP4Command(command))
If response = "" Then
MsgBox "Networking timeout, please try it later!"
GoTo ErrorHandle
End If
If Not IsGoodResponse(response, cmdId) Then
MsgBox response
GoTo ErrorHandle
End If
ErrorHandler:
Call oImap4.Close() 'Close connection
Set oImap4 = Nothing
End Sub
[C#]
public void VerifyResponse( string szId, string response )
{
string s;
s = szId.ToUpper();
s += " OK";
string r = response.ToUpper();
if( r.Length == 0 )
{
throw new Exception( "Networking timeout, please try it later!" );
}
if( r.IndexOf( s ) < 0 )
{
throw new Exception( response );
}
}
public void CreateFolder( string imap4Server, string imap4User, string imap4Password, string folder )
{
POPMAINClass oImap4 = new POPMAINClass(); //Create object instance
int nRet = 0;
try
{
oImap4.IMAP4Connection = 1;
oImap4.ServerPort = 143;
nRet = oImap4.Connect( imap4Server,
imap4User,
imap4Password ); //Connect IMAP4 server
if( nRet != 0 )
throw new Exception( "error with Connect" );
string cmdId, response, command;
cmdId = "A001";
command = String.Format( "{0} CREATE \"{1}\"\r\n", cmdId, oImap4.EncodeIMAP4Folder(folder));
response = oImap4.execIMAP4Command( command ).Trim();
VerifyResponse( cmdId, response );
}
catch( Exception e )
{
Console.WriteLine( e.Message );
}
oImap4.Close(); //Close connection
oImap4 = null;
}
See Also
DecodeIMAP4Folder Method
execIMAP4Command Method
ParseIMAP4Response Method
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.