This commit is contained in:
prasad%netscape.com 1998-08-24 22:38:06 +00:00
Родитель ff49471cb3
Коммит bdbf234eb2
6 изменённых файлов: 1344 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,115 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
#ifndef TESTSINK_H
#define TESTSINK_H
#include <stdio.h>
#include "imap4.h"
void taggedLine(imap4SinkPtr_t in_pimap4Sink, char* in_tag, const char* in_status, const char* in_reason);
void error(imap4SinkPtr_t in_pimap4Sink, const char* in_tag, const char* in_status, const char* in_reason);
void ok(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information);
void no(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information);
void bad(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information);
void rawResponse(imap4SinkPtr_t in_pimap4Sink, const char* in_data);
/*Fetch Response*/
void fetchStart(imap4SinkPtr_t in_pimap4Sink, int in_msg);
void fetchEnd(imap4SinkPtr_t in_pimap4Sink);
void fetchSize(imap4SinkPtr_t in_pimap4Sink, int in_size);
void fetchData(imap4SinkPtr_t in_pimap4Sink, const char* in_data, int in_bytesRead, int in_totalBytes);
void fetchFlags(imap4SinkPtr_t in_pimap4Sink, const char* in_flags);
void fetchBodyStructure(imap4SinkPtr_t in_pimap4Sink, const char* in_bodyStructure);
void fetchEnvelope(imap4SinkPtr_t in_pimap4Sink, const char** in_value, int in_valueLength);
void fetchInternalDate(imap4SinkPtr_t in_pimap4Sink, const char* in_internalDate);
void fetchHeader(imap4SinkPtr_t in_pimap4Sink, const char* in_field, const char* in_value);
void fetchUid(imap4SinkPtr_t in_pimap4Sink, int in_uid);
/*Lsub Response*/
void lsub(imap4SinkPtr_t in_pimap4Sink, const char* in_attribute, const char* in_delimeter, const char* in_name);
/*List Response*/
void list(imap4SinkPtr_t in_pimap4Sink, const char* in_attribute, const char* in_delimeter, const char* in_name);
/*Search Response*/
void searchStart(imap4SinkPtr_t in_pimap4Sink);
void search(imap4SinkPtr_t in_pimap4Sink, int in_message);
void searchEnd(imap4SinkPtr_t in_pimap4Sink);
/*Status Response*/
void statusMessages(imap4SinkPtr_t in_pimap4Sink, int in_messages);
void statusRecent(imap4SinkPtr_t in_pimap4Sink, int in_recent);
void statusUidnext(imap4SinkPtr_t in_pimap4Sink, int in_uidNext);
void statusUidvalidity(imap4SinkPtr_t in_pimap4Sink, int in_uidValidity);
void statusUnseen(imap4SinkPtr_t in_pimap4Sink, int in_unSeen);
/*Capability Response*/
void capability(imap4SinkPtr_t in_pimap4Sink, const char* in_listing);
/*Exists Response*/
void exists(imap4SinkPtr_t in_pimap4Sink, int in_messages);
/*Expunge Response*/
void expunge(imap4SinkPtr_t in_pimap4Sink, int in_message);
/*Recent Response*/
void recent(imap4SinkPtr_t in_pimap4Sink, int in_messages);
/*Flags Response*/
void flags(imap4SinkPtr_t in_pimap4Sink, const char* in_flags);
/*Bye Response*/
void bye(imap4SinkPtr_t in_pimap4Sink, const char* in_reason);
/*Namespace Response*/
void nameSpaceStart(imap4SinkPtr_t in_pimap4Sink);
void nameSpacePersonal(imap4SinkPtr_t in_pimap4Sink, const char* in_personal);
void nameSpaceOtherUsers(imap4SinkPtr_t in_pimap4Sink, const char* in_otherUsers);
void nameSpaceShared(imap4SinkPtr_t in_pimap4Sink, const char* in_shared);
void nameSpaceEnd(imap4SinkPtr_t in_pimap4Sink);
/*ACL Responses*/
void aclStart(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox);
void aclIdentifierRight(imap4SinkPtr_t in_pimap4Sink, const char* in_identifier, const char* in_rights);
void aclEnd(imap4SinkPtr_t in_pimap4Sink);
/*LISTRIGHTS Responses*/
void listRightsStart(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox, const char* in_identifier);
void listRightsRequiredRights(imap4SinkPtr_t in_pimap4Sink, const char* in_requiredRights);
void listRightsOptionalRights(imap4SinkPtr_t in_pimap4Sink, const char* in_optionalRights);
void listRightsEnd(imap4SinkPtr_t in_pimap4Sink);
/*MYRIGHTS Responses*/
void myRights(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox, const char* in_rights);
/*Data Structures*/
char* sink_fetchUIDResults;
boolean bStoreUID;
#endif /*TESTSINK_H*/

Просмотреть файл

@ -0,0 +1,340 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
/*
*This test program demonstrates multi-threaded usage of the IMAP4 module in the
*message SDK. It performs a fetch and a search with two threads and demonstrates
*the use of a mutex.
*USAGE:imaptest.exe server user password mailbox
*NOTE:By default this test program attempts to fetch message 1
*@author derekt@netscape.com
*@version 1.0
*/
#include "imap4.h"
#include "nsStream.h"
#include "testsink.h"
#include <time.h>
#ifdef WIN32
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <stddef.h>
#include <stdlib.h>
#include <conio.h>
#else
#include <pthread.h>
#endif
/* Global Server Error Flag */
boolean g_serverError = FALSE;
/* Global Data */
imap4Client_t * g_pClient;
#ifdef WIN32
HANDLE g_handle;
#else
pthread_t g_threadID1;
pthread_t g_threadID2;
pthread_mutex_t g_mp;
#endif
/*Function prototype for settting sink pointers*/
void setSink( imap4Sink_t * pSink );
void IMAP4_lock();
void IMAP4_unlock();
/*A function to perform a search*/
void IMAP4_SearchThread( void * dummy )
{
char * l_szTagID;
int l_nReturn;
printf( "Inside IMAP4_SearchThread\n" );
IMAP4_lock();
/*Select the INBOX.*/
l_nReturn = imap4_search( g_pClient, "BODY \"World\"", &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
printf( "imaptest.c::IMAP4_SearchThread" );
IMAP4_unlock();
return;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "imaptest.c::IMAP4_SearchThread" );
IMAP4_unlock();
return;
}
IMAP4_unlock();
}
/*A function to perform a fetch*/
void IMAP4_FetchThread( void * dummy )
{
char * l_szTagID;
int l_nReturn;
printf( "Inside IMAP4_FetchThread\n" );
IMAP4_lock();
/*Fetch the message.*/
l_nReturn = imap4_fetch( g_pClient, "1", "(BODY[])", &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
printf( "imaptest.c::IMAP4_SearchThread" );
IMAP4_unlock();
return;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "imaptest.c::IMAP4_SearchThread" );
IMAP4_unlock();
return;
}
IMAP4_unlock();
}
int main( int argc, char *argv[ ] )
{
int l_nReturn;
char * l_szTagID;
unsigned long l_threadHandle1;
unsigned long l_threadHandle2;
imap4Sink_t * pSink = NULL;
g_pClient = NULL;
/*Initialize the response sink.*/
l_nReturn = imap4Sink_initialize( &pSink );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
setSink( pSink );
l_nReturn = imap4_initialize( &g_pClient, pSink );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
/*Connect to the server.*/
l_nReturn = imap4_connect( g_pClient, argv[1], 143, &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
return l_nReturn;
}
/*Login.*/
l_nReturn = imap4_login( g_pClient, argv[2], argv[3], &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
return l_nReturn;
}
/*Select the mailbox.*/
l_nReturn = imap4_select( g_pClient, argv[4], &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
return l_nReturn;
}
/*Setup the mutex and the threads*/
#ifdef WIN32
g_handle = CreateMutex( NULL, FALSE, NULL );
l_threadHandle1 = _beginthread( IMAP4_FetchThread, 0, NULL );
l_threadHandle2 = _beginthread( IMAP4_SearchThread, 0, NULL );
WaitForSingleObject( (HANDLE)l_threadHandle1, INFINITE );
WaitForSingleObject( (HANDLE)l_threadHandle2, INFINITE );
#else
pthread_mutex_init( &g_mp, NULL );
pthread_create( &g_threadID1, NULL, IMAP4_FetchThread, NULL );
pthread_create( &g_threadID2, NULL, IMAP4_SearchThread, NULL );
pthread_join( g_threadID1, NULL );
pthread_join( g_threadID2, NULL );
pthread_mutex_destroy( &g_mp );
#endif
/*Logout.*/
l_nReturn = imap4_logout( g_pClient, &l_szTagID );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
imap4Tag_free(&l_szTagID);
l_nReturn = imap4_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
return l_nReturn;
}
/*Free the client structure.*/
imap4_free( &g_pClient );
/*Free the sink structure.*/
imap4Sink_free( &pSink );
return 0;
}
/*Function to set the sink pointers.*/
void setSink( imap4Sink_t * pSink )
{
pSink->taggedLine = taggedLine;
pSink->error = error;
pSink->ok = ok;
pSink->rawResponse = rawResponse;
pSink->fetchStart = fetchStart;
pSink->fetchEnd = fetchEnd;
pSink->fetchSize = fetchSize;
pSink->fetchData = fetchData;
pSink->fetchFlags = fetchFlags;
pSink->fetchBodyStructure = fetchBodyStructure;
pSink->fetchEnvelope = fetchEnvelope;
pSink->fetchInternalDate = fetchInternalDate;
pSink->fetchHeader = fetchHeader;
pSink->fetchUid = fetchUid;
pSink->lsub = lsub;
pSink->list = list;
pSink->searchStart = searchStart;
pSink->search = search;
pSink->searchEnd = searchEnd;
pSink->statusMessages = statusMessages;
pSink->statusRecent = statusRecent;
pSink->statusUidnext = statusUidnext;
pSink->statusUidvalidity = statusUidvalidity;
pSink->statusUnseen = statusUnseen;
pSink->capability = capability;
pSink->exists = exists;
pSink->expunge = expunge;
pSink->recent = recent;
pSink->flags = flags;
pSink->bye = bye;
pSink->nameSpaceStart = nameSpaceStart;
pSink->nameSpacePersonal = nameSpacePersonal;
pSink->nameSpaceOtherUsers = nameSpaceOtherUsers;
pSink->nameSpaceShared = nameSpaceShared;
pSink->nameSpaceEnd = nameSpaceEnd;
pSink->aclStart = aclStart;
pSink->aclIdentifierRight = aclIdentifierRight;
pSink->aclEnd = aclEnd;
pSink->listRightsStart = listRightsStart;
pSink->listRightsRequiredRights = listRightsRequiredRights;
pSink->listRightsOptionalRights = listRightsOptionalRights;
pSink->listRightsEnd = listRightsEnd;
pSink->myRights = myRights;
}
/*Function to lock the mutex*/
void IMAP4_lock()
{
#ifdef WIN32
if ( WaitForSingleObject( g_handle, INFINITE ) == WAIT_FAILED )
{
printf( "imaptest.c::IMAP4_lock" );
return;
}
#else
if ( pthread_mutex_lock( &g_mp ) != 0 )
{
printf( "imaptest.c::IMAP4_lock" );
return;
}
#endif
}
/*Function to unlock the mutex*/
void IMAP4_unlock()
{
#ifdef WIN32
if ( ReleaseMutex( g_handle ) == 0 )
{
printf( "imaptest.c::IMAP4_unlock" );
return;
}
#else
if ( pthread_mutex_unlock( &g_mp ) != 0 )
{
printf( "imaptest.c::IMAP4_unlock" );
return;
}
#endif
}

Просмотреть файл

@ -0,0 +1,333 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
#include "testsink.h"
extern boolean g_serverError;
void taggedLine(imap4SinkPtr_t in_pimap4Sink, char* in_tag, const char* in_status, const char* in_reason)
{
printf("taggedLine tag: %s\n", in_tag);
printf("taggedLine status: %s\n", in_status);
printf("taggedLine reason: %s\n", in_reason);
}
void error(imap4SinkPtr_t in_pimap4Sink, const char* in_tag, const char* in_status, const char* in_reason)
{
g_serverError = TRUE;
printf("ERROR: %s %s %s\n", in_tag, in_status, in_reason);
}
void ok(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information)
{
if(in_responseCode != NULL)
{
printf("OK code: %s\n", in_responseCode);
}
printf("OK info: %s\n", in_information );
}
void no(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information)
{
if(in_responseCode != NULL)
{
printf("NO code: %s\n", in_responseCode);
}
printf("NO info: %s\n", in_information );
}
void bad(imap4SinkPtr_t in_pimap4Sink, const char* in_responseCode, const char* in_information)
{
if(in_responseCode != NULL)
{
printf("BAD code: %s\n", in_responseCode);
}
printf("BAD info: %s\n", in_information );
}
void rawResponse(imap4SinkPtr_t in_pimap4Sink, const char* in_data)
{
printf("RAWRESPONSE: %s\n", in_data);
}
/*Fetch Response*/
void fetchStart(imap4SinkPtr_t in_pimap4Sink, int in_msg)
{
printf("FetchStart: %d\n", in_msg);
}
void fetchEnd(imap4SinkPtr_t in_pimap4Sink)
{
printf("fetchEnd\n");
}
void fetchSize(imap4SinkPtr_t in_pimap4Sink, int in_size)
{
printf("fetchSize: %d\n", in_size);
}
void fetchData(imap4SinkPtr_t in_pimap4Sink, const char* in_data, int in_bytesRead, int in_totalBytes)
{
printf("fetchData: %s\n BytesRead: %d TotalBytes: %d\n", in_data, in_bytesRead, in_totalBytes);
}
void fetchFlags(imap4SinkPtr_t in_pimap4Sink, const char* in_flags)
{
printf("fetchFlags: %s\n", in_flags);
}
void fetchBodyStructure(imap4SinkPtr_t in_pimap4Sink, const char* in_bodyStructure)
{
printf("fetchBodyStructure: %s\n", in_bodyStructure);
}
void fetchEnvelope(imap4SinkPtr_t in_pimap4Sink, const char** in_value, int in_valueLength)
{
int i=0;
for(i=0; i<in_valueLength; i++)
{
printf("fetchEnvelope: %s\n", in_value[i]);
}
}
void fetchInternalDate(imap4SinkPtr_t in_pimap4Sink, const char* in_internalDate)
{
printf("fetchInternalDate: %s\n", in_internalDate);
}
void fetchHeader(imap4SinkPtr_t in_pimap4Sink, const char* in_field, const char* in_value)
{
printf("fetchHeader:%s Value:%s\n", in_field, in_value);
}
void fetchUid(imap4SinkPtr_t in_pimap4Sink, int in_uid)
{
char l_buffer[100];
if(bStoreUID)
{
if(sink_fetchUIDResults == NULL)
{
/*Arbitrary size for quick test*/
sink_fetchUIDResults = (char*)malloc(100*sizeof(char));
if(sink_fetchUIDResults == NULL)
{
return;
}
memset(sink_fetchUIDResults, 0, 100*sizeof(char));
}
else
{
strcat(sink_fetchUIDResults, ":");
}
sprintf(l_buffer, "%d", in_uid);
strcat(sink_fetchUIDResults, l_buffer);
printf("fetchUid: %s\n", sink_fetchUIDResults);
}
else
{
printf("fetchUid: %d\n", in_uid);
}
}
/*Lsub Response*/
void lsub(imap4SinkPtr_t in_pimap4Sink, const char* in_attribute, const char* in_delimeter, const char* in_name)
{
printf("lsub attribute: %s\n", in_attribute);
printf("lsub delimeter: %s\n", in_delimeter);
printf("lsub name: %s\n", in_name);
}
/*List Response*/
void list(imap4SinkPtr_t in_pimap4Sink, const char* in_attribute, const char* in_delimeter, const char* in_name)
{
printf("list attribute: %s\n", in_attribute);
printf("list delimeter: %s\n", in_delimeter);
printf("list name: %s\n", in_name);
}
/*Search Response*/
void searchStart(imap4SinkPtr_t in_pimap4Sink)
{
printf("searchStart\n");
}
void search(imap4SinkPtr_t in_pimap4Sink, int in_message)
{
printf("search: %d\n", in_message);
}
void searchEnd(imap4SinkPtr_t in_pimap4Sink)
{
printf("searchEnd\n");
}
/*Status Response*/
void statusMessages(imap4SinkPtr_t in_pimap4Sink, int in_messages)
{
printf("statusMessages: %d\n", in_messages);
}
void statusRecent(imap4SinkPtr_t in_pimap4Sink, int in_recent)
{
printf("statusRecent: %d\n", in_recent);
}
void statusUidnext(imap4SinkPtr_t in_pimap4Sink, int in_uidNext)
{
printf("statusUidnext: %d\n", in_uidNext);
}
void statusUidvalidity(imap4SinkPtr_t in_pimap4Sink, int in_uidValidity)
{
printf("statusUidvalidity: %d\n", in_uidValidity);
}
void statusUnseen(imap4SinkPtr_t in_pimap4Sink, int in_unSeen)
{
printf("statusUnseen: %d\n", in_unSeen);
}
/*Capability Response*/
void capability(imap4SinkPtr_t in_pimap4Sink, const char* in_listing)
{
printf("capability: %s\n", in_listing);
}
/*Exists Response*/
void exists(imap4SinkPtr_t in_pimap4Sink, int in_messages)
{
printf("exists: %d\n", in_messages);
}
/*Expunge Response*/
void expunge(imap4SinkPtr_t in_pimap4Sink, int in_message)
{
printf("expunge: %d\n", in_message);
}
/*Recent Response*/
void recent(imap4SinkPtr_t in_pimap4Sink, int in_messages)
{
printf("recent: %d\n", in_messages);
}
/*Flags Response*/
void flags(imap4SinkPtr_t in_pimap4Sink, const char* in_flags)
{
printf("flags: %s\n", in_flags);
}
/*Bye Response*/
void bye(imap4SinkPtr_t in_pimap4Sink, const char* in_reason)
{
printf("bye: %s\n", in_reason);
}
/*Namespace Response*/
void nameSpaceStart(imap4SinkPtr_t in_pimap4Sink)
{
printf("nameSpaceStart\n");
}
void nameSpacePersonal(imap4SinkPtr_t in_pimap4Sink, const char* in_personal)
{
printf("nameSpacePersonal %s\n", in_personal);
}
void nameSpaceOtherUsers(imap4SinkPtr_t in_pimap4Sink, const char* in_otherUsers)
{
printf("nameSpaceOtherUsers: %s\n", in_otherUsers);
}
void nameSpaceShared(imap4SinkPtr_t in_pimap4Sink, const char* in_shared)
{
printf("nameSpaceShared: %s\n", in_shared);
}
void nameSpaceEnd(imap4SinkPtr_t in_pimap4Sink)
{
printf("nameSpaceEnd\n");
}
/*ACL Responses*/
void aclStart(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox)
{
printf("aclStart: %s\n", in_mailbox);
}
void aclIdentifierRight(imap4SinkPtr_t in_pimap4Sink, const char* in_identifier, const char* in_rights)
{
printf("aclIdentifierRight: %s %s\n", in_identifier, in_rights);
}
void aclEnd(imap4SinkPtr_t in_pimap4Sink)
{
printf("aclEnd\n");
}
/*LISTRIGHTS Responses*/
void listRightsStart(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox, const char* in_identifier)
{
printf("listRightsStart: %s %s\n", in_mailbox, in_identifier);
}
void listRightsRequiredRights(imap4SinkPtr_t in_pimap4Sink, const char* in_requiredRights)
{
printf("listRightsRequiredRights: %s\n", in_requiredRights);
}
void listRightsOptionalRights(imap4SinkPtr_t in_pimap4Sink, const char* in_optionalRights)
{
printf("listRightsOptionalRights: %s\n", in_optionalRights);
}
void listRightsEnd(imap4SinkPtr_t in_pimap4Sink)
{
printf("listRightsEnd\n");
}
/*MYRIGHTS Responses*/
void myRights(imap4SinkPtr_t in_pimap4Sink, const char* in_mailbox, const char* in_rights)
{
printf("myRights: %s %s\n", in_mailbox, in_rights);
}

Просмотреть файл

@ -0,0 +1,55 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
/*
*@author derekt@netscape.com
*@version 1.0
*/
#ifndef TESTSINK_H
#define TESTSINK_H
#include <stdio.h>
void SMTPTest_bdat( smtpSink_t *, int, const char * );
void SMTPTest_connect( smtpSink_t *, int, const char * );
void SMTPTest_data( smtpSink_t *, int, const char * );
void SMTPTest_ehlo( smtpSink_t *, int, const char * );
void SMTPTest_ehloComplete(smtpSink_t *);
void SMTPTest_expand( smtpSink_t *, int, const char * );
void SMTPTest_expandComplete(smtpSink_t *);
void SMTPTest_help( smtpSink_t *, int, const char * );
void SMTPTest_helpComplete(smtpSink_t *);
void SMTPTest_mailFrom( smtpSink_t *, int, const char * );
void SMTPTest_noop( smtpSink_t *, int, const char * );
void SMTPTest_quit( smtpSink_t *, int, const char * );
void SMTPTest_rcptTo( smtpSink_t *, int, const char * );
void SMTPTest_reset( smtpSink_t *, int, const char * );
void SMTPTest_send( smtpSink_t *, int, const char * );
void SMTPTest_sendCommand( smtpSink_t *, int, const char * );
void SMTPTest_sendCommandComplete(smtpSink_t *);
void SMTPTest_verify( smtpSink_t *, int, const char * );
#endif /* TESTSINK_H */

Просмотреть файл

@ -0,0 +1,351 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
/*
*This test program demonstrates multi-threaded usage of the SMTP module in the
*message SDK. It starts a thread to send a message and uses another thread to
*cancel it.
*USAGE:smtptest.exe server domain sender recipient data
*NOTE: data must be 1 word
*@author derekt@netscape.com
*@version 1.0
*/
#include "smtp.h"
#include "nsStream.h"
#include "testsink.h"
#include <time.h>
#ifdef WIN32
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <stddef.h>
#include <stdlib.h>
#include <conio.h>
#else
#include <pthread.h>
#endif
/* Global Server Error Flag */
boolean g_serverError = FALSE;
/* Global Data */
smtpClient_t * g_pClient;
char * g_szServer;
char * g_szDomain;
char * g_szSender;
char * g_szRecipient;
char * g_szData;
#ifdef WIN32
HANDLE g_handle;
HANDLE g_threadHandle;
#else
pthread_t g_threadID1;
pthread_t g_threadID2;
pthread_mutex_t g_mp;
#endif
/*Function prototype for settting sink pointers*/
void setSink( smtpSink_t * pSink );
void SMTP_lock();
void SMTP_unlock();
/*Perform a disconnect from the server*/
void SMTP_CancelThread( void * dummy )
{
int l_nReturn = smtp_disconnect( g_pClient );
printf( "Inside CancelThread\n" );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_CancelThread" );
return;
}
}
/*Attempt to send a message*/
void SMTP_SendThread( void * dummy )
{
int l_nReturn;
SMTP_lock();
/*Connect to the SMTP server.*/
l_nReturn = smtp_connect( g_pClient, g_szServer, 25 );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
/*Send the EHLO command passing in the domain name.*/
l_nReturn = smtp_ehlo( g_pClient, g_szDomain );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
/*Send the MAIL FROM command.*/
l_nReturn = smtp_mailFrom( g_pClient, g_szSender, NULL );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
/*Send the RCPT TO command.*/
l_nReturn = smtp_rcptTo( g_pClient, g_szRecipient, NULL );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
/*Send the DATA command.*/
l_nReturn = smtp_data( g_pClient );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
/* Send the message.*/
l_nReturn = smtp_send( g_pClient, g_szData );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_quit( g_pClient );
if ( l_nReturn != NSMAIL_OK )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
l_nReturn = smtp_processResponses( g_pClient );
if ( l_nReturn != NSMAIL_OK || g_serverError == TRUE )
{
printf( "smtptest.c::SMTP_SendThread" );
SMTP_unlock();
return;
}
SMTP_unlock();
}
int main( int argc, char *argv[] )
{
int l_nReturn;
unsigned long l_threadHandle1;
unsigned long l_threadHandle2;
smtpSink_t * pSink = NULL;
g_pClient = NULL;
/*Initialize the global parameters*/
g_szServer = argv[1];
g_szDomain = argv[2];
g_szSender = argv[3];
g_szRecipient = argv[4];
g_szData = argv[5];
/*Initialize the response sink.*/
l_nReturn = smtpSink_initialize( &pSink );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
/*Set the function pointers on the response sink.*/
setSink( pSink );
/*Initialize the client passing in the response sink.*/
l_nReturn = smtp_initialize( &g_pClient, pSink );
if ( l_nReturn != NSMAIL_OK )
{
return l_nReturn;
}
/*Setup the mutex and the threads*/
#ifdef WIN32
g_handle = CreateMutex( NULL, FALSE, NULL );
l_threadHandle1 = _beginthread( SMTP_SendThread, 0, NULL );
l_threadHandle2 = _beginthread( SMTP_CancelThread, 0, NULL );
WaitForSingleObject( (HANDLE)l_threadHandle1, INFINITE );
WaitForSingleObject( (HANDLE)l_threadHandle2, INFINITE );
#else
pthread_mutex_init( &g_mp, NULL );
pthread_create( &g_threadID1, NULL, SMTP_SendThread, NULL );
pthread_create( &g_threadID2, NULL, SMTP_CancelThread, NULL );
pthread_join( g_threadID1, NULL );
pthread_join( g_threadID2, NULL );
pthread_mutex_destroy( &g_mp );
#endif
/*Free the client structure.*/
smtp_free( &g_pClient );
/*Free the sink structure.*/
smtpSink_free( &pSink );
return 0;
}
/*Function to set the sink pointers.*/
void setSink( smtpSink_t * pSink )
{
pSink->bdat = SMTPTest_bdat;
pSink->connect = SMTPTest_connect;
pSink->data = SMTPTest_data;
pSink->ehlo = SMTPTest_ehlo;
pSink->ehloComplete = SMTPTest_ehloComplete;
pSink->expand = SMTPTest_expand;
pSink->expandComplete = SMTPTest_expandComplete;
pSink->help = SMTPTest_help;
pSink->helpComplete = SMTPTest_helpComplete;
pSink->mailFrom = SMTPTest_mailFrom;
pSink->noop = SMTPTest_noop;
pSink->quit = SMTPTest_quit;
pSink->rcptTo = SMTPTest_rcptTo;
pSink->reset = SMTPTest_reset;
pSink->send = SMTPTest_send;
pSink->sendCommand = SMTPTest_sendCommand;
pSink->sendCommandComplete = SMTPTest_sendCommandComplete;
pSink->verify = SMTPTest_verify;
}
/*Function to lock the mutex*/
void SMTP_lock()
{
#ifdef WIN32
if ( WaitForSingleObject( g_handle, INFINITE ) == WAIT_FAILED )
{
printf( "smtptest.c::SMTP_lock" );
return;
}
#else
if ( pthread_mutex_lock( &g_mp ) != 0 )
{
printf( "smtptest.c::SMTP_lock" );
return;
}
#endif
}
/*Function to unlock the mutex*/
void SMTP_unlock()
{
#ifdef WIN32
if ( ReleaseMutex( g_handle ) == 0 )
{
printf( "smtptest.c::SMTP_unlock" );
return;
}
#else
if ( pthread_mutex_unlock( &g_mp ) != 0 )
{
printf( "smtptest.c::SMTP_unlock" );
return;
}
#endif
}

Просмотреть файл

@ -0,0 +1,150 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
* released on or about June 15, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
* Communications Corporation. All Rights Reserved.
*
* Contributor(s): ______________________________________.
*/
/*
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
* (http://home.netscape.com/misc/trademarks.html)
*/
#include "smtp.h"
#include "testsink.h"
/*
*Notification sink for SMTP commands.
*@author derekt@netscape.com
*@version 1.0
*/
extern boolean g_serverError;
/*Notification for the response to the BDAT command.*/
void SMTPTest_bdat( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the connection to the server.*/
void SMTPTest_connect( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the DATA command.*/
void SMTPTest_data( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the EHLO command.*/
void SMTPTest_ehlo( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the completion of the EHLO command.*/
void SMTPTest_ehloComplete(smtpSink_t * in_pSink)
{
printf( "EHLO complete\n" );
}
/*Notification for the response to a server error.*/
void SMTPTest_error(smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
g_serverError = TRUE;
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the EXPN command.*/
void SMTPTest_expand( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the completion of the EXPN command.*/
void SMTPTest_expandComplete(smtpSink_t * in_pSink)
{
printf( "EXPAND complete\n" );
}
/*Notification for the response to the HELP command.*/
void SMTPTest_help( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the completion of the HELP command.*/
void SMTPTest_helpComplete(smtpSink_t * in_pSink)
{
printf( "HELP complete\n" );
}
/*Notification for the response to the MAIL FROM command.*/
void SMTPTest_mailFrom( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the NOOP command.*/
void SMTPTest_noop( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the QUIT command.*/
void SMTPTest_quit( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the RCPT TO command.*/
void SMTPTest_rcptTo( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to the RSET command.*/
void SMTPTest_reset( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to sending the message.*/
void SMTPTest_send( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the response to sending a generic command.*/
void SMTPTest_sendCommand( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}
/*Notification for the completion of send a generic command.*/
void SMTPTest_sendCommandComplete(smtpSink_t * in_pSink)
{
printf( "SENDCOMMAND complete\n" );
}
/*Notification for the response to the VRFY command.*/
void SMTPTest_verify( smtpSink_t * in_pSink, int in_responseCode, const char * in_responseMessage )
{
printf( "%d %s\n", in_responseCode, in_responseMessage );
}