email/pop3andsmtpmtm/smtpservermtm/src/SMTSUTIL.CPP
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Internet SMTP Transport Driver - utility functions
       
    15 // 
       
    16 //
       
    17 
       
    18 #include<e32std.h>
       
    19 //Oyster includes
       
    20 #include<msvstd.h>
       
    21 //IMSK includes
       
    22 #include<imsk.h>
       
    23 //SMTS includes
       
    24 #include"SMTS.H"
       
    25 #include"IMSM.H"
       
    26 #include"SMTSUTIL.H"
       
    27 
       
    28 GLDEF_C void gPanic(TSmtsAssertError aReason)
       
    29 	{
       
    30 	User::Panic(_L("SMTS-DLL"),aReason);
       
    31 	}
       
    32 
       
    33 
       
    34 GLDEF_C void RequestComplete(TRequestStatus& aStatus,TInt aCompletion)
       
    35 	{
       
    36 	// Untility function which sends completion signal to client active object
       
    37 	TRequestStatus* statusPtr=&aStatus;
       
    38 	User::RequestComplete(statusPtr,aCompletion);
       
    39 	}
       
    40 
       
    41 
       
    42 GLDEF_C TBool LastSmtpCommandAccepted(TInt aSmtpCode,TInt aRequiredFirstDigit)
       
    43 	{
       
    44 	// Utility function: is 1st digit of 3-digit code returned by SMTP server
       
    45 	// the digit we expected? Returns true or False.
       
    46 	// Used as a simple test to determine whether last command sent to remote SMTP server
       
    47 	// was accepted or not.
       
    48 	//
       
    49 	// E.g. aSmtpCode=250 ; test for aRequiredFirstDigit=2
       
    50 	// or   aSmtpCode=354 ; test for aRequiredFirstDigit=3
       
    51 	
       
    52 	return ((aSmtpCode/100)==aRequiredFirstDigit);
       
    53 	}
       
    54 
       
    55 
       
    56 GLDEF_C TInt SmtpResponseCode(const TDesC8& aTextLine,TBool& aMultiLineResponse,TBool& aLastMultiLineResponse)
       
    57 	{
       
    58 	// This function examines the response from remote SMTP server to determine
       
    59 	// whether the most recent SMTP command sent to that server by this transport driver
       
    60 	// was accepted, or not. Also determines whether it is one of a multi-line response
       
    61 	// from the server (as sent by ESMTP servers)
       
    62 	//
       
    63 	// SMTP return codes are always 3 digit numbers, where:
       
    64 	//		"2xx" is a positive response (ie command was accepted)
       
    65 	//		"354" is a positive response to the "DATA" command
       
    66 	//		"4xx" is a negative reply - temporary error in remote SMTP server
       
    67 	//		"5xx" is a negative reply  - error in commmand sent to remote SMPT server by this transport driver
       
    68 
       
    69 	TLex8   parseResponse(aTextLine);
       
    70 	TInt    SmtpCode;
       
    71 	if (!parseResponse.Val(SmtpCode))
       
    72 		{
       
    73 		// remember state of iSmtpMultiLine flag; value is used by parseMultiLineResponse
       
    74 		aLastMultiLineResponse = aMultiLineResponse;
       
    75 		aMultiLineResponse = (parseResponse.Get().IsSpace()==EFalse);
       
    76 		aLastMultiLineResponse &= !aMultiLineResponse;
       
    77 		return (SmtpCode);
       
    78 		}
       
    79 	// If TLex failed, response from SMTP server was bogus - ie it contained no 3-digit return code.
       
    80 	// So generate a fake one to ensure that state machine is notified of this error
       
    81 	return (ESmtpNoReturnCode);	
       
    82 	}
       
    83 
       
    84 
       
    85 GLDEF_C TInt IdentifySmtpError(TInt aSmtpErrorCode)
       
    86 	{
       
    87 	// Error codes which may be returned in response to any SMTP command
       
    88 	switch (aSmtpErrorCode)
       
    89 		{
       
    90 	case 421:
       
    91 //		error=ESmtpServiceNotAvailable;		// service not available
       
    92 	case 450:
       
    93 //		error=ESmtpMailboxUnavailable;
       
    94 	case 451: 
       
    95 //		error=ESmtpActionAborted;			// processing error on remote SMTP server
       
    96 	case 452:
       
    97 //		error=ESmtpActionNotTaken;			// insufficient storage on remote SMTP server
       
    98 	case 500:
       
    99 //		error=ESmtpCommandUnrecognised;		// Bug in IMSM.DLL? ; sending illegal command to remote SMTP server
       
   100 	case 501:
       
   101 //		error=ESmtpSyntaxError;				// Bug in IMSM.DLL? ; incorrect syntax in command sent to remote SMTP server
       
   102 	case 502:
       
   103 //		error=ESmtpCommmandNotImplemented;	// Command sent to SMTP server not recognised by that server.
       
   104 	case 503:
       
   105 //		error=ESmtpBadSequence;				// Bug in IMSM's state machine? ; SMTP commands sent to server in wrong order
       
   106 	case 504:
       
   107 //		error=ESmtpParamNotImplemented;		// Bug in IMSM.DLL? ; SMTP server didn't expect parameter with this command
       
   108 	case 550:
       
   109 //		error=ESmtpMailboxNoAccess;			// Mailbox not found, or no access to mailbox on remote SMTP server
       
   110 	case 551:
       
   111 //		error=ESmtpUserNotLocal;			// Remote SMTP server expects a forward path
       
   112 	case 552:
       
   113 //		error=ESmtpExceededStorage;			// Insuffucient storage space on remote SMTP server for message
       
   114 	case 553:
       
   115 //		error=ESmtpMailboxName;				// Bug in IMSM.DLL? ; Mailbox name not allowed
       
   116 	case 554:
       
   117 //		error=ESmtpTransactionFailed;		// Transaction failed!
       
   118 
       
   119 		// I recognised SMTP error code
       
   120 		return aSmtpErrorCode;
       
   121 		}
       
   122 
       
   123 	// i.e. didn't recognise error code - so must be a socket/Epoc32 error
       
   124 	return 0;
       
   125 	}