email/pop3andsmtpmtm/clientmtms/src/MIUTSET.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 //
       
    15 
       
    16 #include "MIUTSET.H"
       
    17 #include "MIUT_ERR.H"
       
    18 
       
    19 
       
    20 GLREF_C TPtrC8 LimitStringSize(const TPtrC8& aString, TInt aMaxSize);
       
    21 GLREF_C TPtrC16 LimitStringSize(const TPtrC16& aString, TInt aMaxSize);
       
    22 
       
    23 
       
    24 EXPORT_C CImBaseEmailSettings::CImBaseEmailSettings()
       
    25 /** 
       
    26 Allocates and creates a new CImBaseEmailSettings object initialised to
       
    27 default values.
       
    28 
       
    29 @internalComponent
       
    30 */
       
    31 	{
       
    32 	Reset();
       
    33 	}
       
    34 
       
    35 
       
    36 EXPORT_C CImBaseEmailSettings::~CImBaseEmailSettings()
       
    37 /**
       
    38 Destructor.
       
    39 
       
    40 @internalComponent
       
    41 */
       
    42 	{
       
    43 	Reset();
       
    44 	}
       
    45 
       
    46 
       
    47 EXPORT_C void CImBaseEmailSettings::Reset()
       
    48 /**
       
    49 Resets the settings to their default values.
       
    50 
       
    51 @internalComponent
       
    52 */
       
    53 	{
       
    54 	delete iServerAddress;
       
    55 	iServerAddress = NULL;
       
    56 	
       
    57 
       
    58 	iFlags=0;
       
    59 	iPortNumber=0;
       
    60 	}
       
    61 
       
    62 
       
    63 EXPORT_C const TPtrC CImBaseEmailSettings::ServerAddress() const
       
    64 /**
       
    65 Retrieves the configured IP address or host name of the email server.
       
    66 The IP address or hostname is configured by calling SetServerAddressL().
       
    67 
       
    68 If an instance of this class is of type CImPop3Settings or CImImap4Settings,
       
    69 the address should be the incoming POP3 or IMAP4 email server.
       
    70 If an instance of this class is of type CImSmtpSettings, the address should
       
    71 be the outbound SMTP email server.
       
    72 
       
    73 The default setting is empty. 
       
    74 
       
    75 @see CImPop3Settings
       
    76 @see CImImap4Settings
       
    77 @see CImSmtpSettings
       
    78 
       
    79 @return
       
    80 Email server IP address if it is configured, or empty if not configured.
       
    81 */
       
    82 	{
       
    83 	return iServerAddress ? TPtrC(*iServerAddress) : TPtrC();
       
    84 	}
       
    85 
       
    86 
       
    87 EXPORT_C TUint CImBaseEmailSettings::Port() const
       
    88 /**
       
    89 Retrieves the port number of an email server when establishing
       
    90 a TCP connection. The port number is configured by calling
       
    91 SetPort().
       
    92 
       
    93 If an instance of this class is of type CImPop3Settings, 
       
    94 the default port number is 110.
       
    95 If an instance of this class is of type CImImap4Settings,
       
    96 the default port number is 143.
       
    97 If an instance of this class is of type CImSmtpSettings,
       
    98 the default port number is 25.
       
    99 
       
   100 @see CImPop3Settings
       
   101 @see CImImap4Settings
       
   102 @see CImSmtpSettings
       
   103 
       
   104 @return
       
   105 Email server TCP port number.
       
   106 */
       
   107 	{
       
   108 	return iPortNumber;
       
   109 	}
       
   110 
       
   111 
       
   112 EXPORT_C void CImBaseEmailSettings::SetServerAddressL(const TDesC& aServerAddress)
       
   113 /**
       
   114 If an instance of this class is of type CImPop3Settings or CImImap4Settings,
       
   115 the address should be the incoming POP3 or IMAP4 email server.
       
   116 If an instance of this class is of type CImSmtpSettings, the address should
       
   117 be the outbound SMTP email server.
       
   118 
       
   119 The default setting is empty. 
       
   120 
       
   121 @see CImPop3Settings
       
   122 @see CImImap4Settings
       
   123 @see CImSmtpSettings
       
   124 
       
   125 @param aServerAddress
       
   126 Email server IP address.
       
   127 */
       
   128 	{
       
   129 	HBufC* newServerAddress = aServerAddress.AllocL();
       
   130 	delete iServerAddress;
       
   131 	iServerAddress = newServerAddress;
       
   132 	}
       
   133 
       
   134 
       
   135 EXPORT_C void CImBaseEmailSettings::SetPort(const TUint aPortNumber)
       
   136 /**
       
   137 Configures the port number of an email server when establishing
       
   138 a TCP connection.
       
   139 
       
   140 If an instance of this class is of type CImPop3Settings, 
       
   141 the default port number is 110.
       
   142 If an instance of this class is of type CImImap4Settings,
       
   143 the default port number is 143.
       
   144 If an instance of this class is of type CImSmtpSettings,
       
   145 the default port number is 25.
       
   146 
       
   147 @see CImPop3Settings
       
   148 @see CImImap4Settings
       
   149 @see CImSmtpSettings
       
   150 
       
   151 @param aPortNumber
       
   152 Email server TCP port number.
       
   153 */
       
   154 	{
       
   155 	iPortNumber = aPortNumber;
       
   156 	}
       
   157 
       
   158 
       
   159 EXPORT_C TBool CImBaseEmailSettings::SecureSockets() const
       
   160 /** 
       
   161 Retrieves whether a secure TLS connection will be negotiated over an
       
   162 unsecure TCP socket connection when a connection is being established.
       
   163 This setting is configured by calling SetSecureSockets().
       
   164 
       
   165 Refer to RFC 2595 - "Using TLS with IMAP, POP3 and ACAP" for information
       
   166 on how a secure socket is established when retrieving email from a POP3
       
   167 or IMAP4 server.
       
   168 
       
   169 Refer to RFC 3207 - "SMTP Service Extension for Secure SMTP over Transport
       
   170 Layer Security" for information on how a secure socket is established when
       
   171 sending an email. 
       
   172 
       
   173 @return
       
   174 ETrue if a secure sockets is enabled.
       
   175 */
       
   176 	{
       
   177 	if(iFlags & EBaseEmailSettingsSecureSockets)
       
   178 		{
       
   179 		return ETrue;
       
   180 		}
       
   181 	else
       
   182 		{
       
   183 		return EFalse;
       
   184 		}		
       
   185 	}
       
   186 
       
   187 
       
   188 EXPORT_C void CImBaseEmailSettings::SetSecureSockets(TBool aFlag)
       
   189 /** 
       
   190 Sets whether a secure TLS connection will be negotiated over an
       
   191 unsecure socket when a connection is being established. This setting
       
   192 is configured by calling SetSecureSockets().
       
   193 
       
   194 Refer to RFC 2595 - "Using TLS with IMAP, POP3 and ACAP" for information
       
   195 on how a secure socket is established when retrieving email from a POP3
       
   196 or IMAP4 server.
       
   197 
       
   198 Refer to RFC 3207 - "SMTP Service Extension for Secure SMTP over Transport
       
   199 Layer Security" for information on how a secure socket is established when
       
   200 sending an email. 
       
   201 
       
   202 Not all POP3, IMAP4, or SMTP servers support this protocol.
       
   203 
       
   204 @post
       
   205 If aFlag is ETrue, secure TLS connection will be disabled if it had been
       
   206 previously been enabled by calling SetSSLWrapper().
       
   207 
       
   208 @param aFlag
       
   209 ETrue if a secure socket session will be negotiated after establishing
       
   210 a non-secure TCP connection with the POP3, IMAP4, or SMTP server.
       
   211 */
       
   212 	{
       
   213 	iFlags = (iFlags & ~EBaseEmailSettingsSecureSockets) | (aFlag?EBaseEmailSettingsSecureSockets : EBaseEmailSettingsClearFlag);
       
   214 
       
   215 	// Ensure that SSLWrapper AND SecureSockets are not BOTH set
       
   216 	if (aFlag && SSLWrapper())
       
   217 		{
       
   218 		SetSSLWrapper(EFalse);
       
   219 		}
       
   220 	}
       
   221 
       
   222 
       
   223 EXPORT_C TBool CImBaseEmailSettings::SSLWrapper() const
       
   224 /**
       
   225 Whether secure sockets will be used. 
       
   226 
       
   227 Retrieves whether a secure TLS connection will be established 
       
   228 directly over a TLS/SSL socket when connecting to the email server.
       
   229 
       
   230 The well known port number for a secure TLS POP3 connection is 995.
       
   231 The well known port number for a secure TLS IMAP4 connection is 993.
       
   232 There is no well known port number for a secure SMTP TLS connection.
       
   233 The TLS/SSL port number that the email server is listening on may not
       
   234 necessarily be configured to the well known port number.
       
   235 The port number upon which the connection is attempted is configured
       
   236 by calling SetPort(). 
       
   237 
       
   238 @return
       
   239 ETrue if a secure TLS connection will be attempted when establishing
       
   240 a connection.
       
   241 */
       
   242 	{
       
   243 	if(iFlags & EBaseEmailSettingsSSLWrappedSockets)
       
   244 		{
       
   245 		return ETrue;
       
   246 		}
       
   247 	else
       
   248 		{
       
   249 		return EFalse;
       
   250 		}		
       
   251 	}
       
   252 
       
   253 
       
   254 EXPORT_C void CImBaseEmailSettings::SetSSLWrapper(TBool aFlag)
       
   255 /**
       
   256 Specifies whether a secure TLS connection will be established 
       
   257 directly over a TLS socket when connecting to the email server.
       
   258 
       
   259 The well known port number for a secure TLS POP3 connection is 995.
       
   260 The well known port number for a secure TLS IMAP4 connection is 993.
       
   261 There is no well known port number for a secure SMTP TLS connection.
       
   262 The TLS/SSL port number that the email server is listening on may not
       
   263 necessarily be configured to the well known port number.
       
   264 The port number upon which the connection is attempted is configured
       
   265 by calling SetPort(). 
       
   266 
       
   267 @post
       
   268 If aFlag is ETrue, secure socket negotiation over an unsecure connection
       
   269 will be disabled if it had been previously enabled by calling
       
   270 SetSecureSockets().
       
   271 
       
   272 @param aFlag
       
   273 If ETrue, a secure TLS connection will be established 
       
   274 when connecting to the email server.
       
   275 */
       
   276 	{
       
   277 	iFlags = (iFlags & ~EBaseEmailSettingsSSLWrappedSockets) | (aFlag?EBaseEmailSettingsSSLWrappedSockets : EBaseEmailSettingsClearFlag);
       
   278 
       
   279 	// Ensure that SSLWrapper AND SecureSockets are not BOTH set
       
   280 	if (aFlag && SecureSockets())
       
   281 		{
       
   282 		SetSecureSockets(EFalse);
       
   283 		}
       
   284 	}
       
   285 
       
   286 
       
   287 EXPORT_C CImBaseEmailSettings& CImBaseEmailSettings::CopyL(const CImBaseEmailSettings& aCImBaseEmailSettings)
       
   288 /**
       
   289 Copies the configuration settings from another service settings object
       
   290 into this object.
       
   291 
       
   292 @param aCImBaseEmailSettings
       
   293 Specifies the object to copy.
       
   294 
       
   295 @return
       
   296 This object after copying.
       
   297 
       
   298 @internalComponent
       
   299 */	
       
   300 	{
       
   301 	Reset();
       
   302 	iPortNumber		=	aCImBaseEmailSettings.iPortNumber;
       
   303 	iFlags			=	aCImBaseEmailSettings.iFlags;
       
   304 #ifdef __SUPPORT_MESSAGING_API_V1	
       
   305 	iData			=	aCImBaseEmailSettings.iData;
       
   306 #endif	
       
   307 	iServerAddress	=	aCImBaseEmailSettings.ServerAddress().AllocL();
       
   308 	return (*this);
       
   309 	}
       
   310 
       
   311 
       
   312 EXPORT_C TBool CImBaseEmailSettings::operator==(const CImBaseEmailSettings& aCImBaseEmailSettings) const
       
   313 /**
       
   314 Equality operator.
       
   315 
       
   316 @param aCImBaseEmailSettings
       
   317 Specifies the settings object to compare with.
       
   318 
       
   319 @return
       
   320 ETrue if the settings are the same.
       
   321 
       
   322 @internalComponent
       
   323 */
       
   324 	{
       
   325 	return (
       
   326 			(Port()			==	aCImBaseEmailSettings.iPortNumber) &&
       
   327 			(iFlags			==	aCImBaseEmailSettings.iFlags) &&
       
   328 			!(ServerAddress().Compare(aCImBaseEmailSettings.ServerAddress())));
       
   329 	}
       
   330 
       
   331 TUint32 CImBaseEmailSettings::SettingsFlags() const
       
   332 	{
       
   333 	return iFlags;
       
   334 	}
       
   335 
       
   336 void CImBaseEmailSettings::SetSettingsFlags(TUint32 aSetFlags)
       
   337 	{
       
   338 	iFlags = aSetFlags;
       
   339 	}
       
   340 
       
   341 /**
       
   342 Sets flag to indicate bearer mobility will be supported by the service.
       
   343 default 0 shall indicate that bearer mobility is not supported.
       
   344  
       
   345 
       
   346 @param aFlag
       
   347 Specifies the new value of the Flag to be set.
       
   348 
       
   349 @return
       
   350 void
       
   351 
       
   352 @internalComponent
       
   353 */	
       
   354 EXPORT_C void CImBaseEmailSettings::SetBearerMobility(TBool aFlag)
       
   355 	{
       
   356 	iFlags = (iFlags & ~EBaseEmailSettingsBearerMobFlag) | (aFlag?EBaseEmailSettingsBearerMobFlag : EBaseEmailSettingsClearFlag);
       
   357 	}
       
   358 
       
   359 /**
       
   360 Indicates whether bearer mobility is supported by the service.
       
   361  
       
   362 @param
       
   363 None
       
   364 
       
   365 @return
       
   366 ETrue if bearer mobility is supported by the service, EFalse otherwise.
       
   367 
       
   368 @internalComponent
       
   369 */	
       
   370 EXPORT_C TBool CImBaseEmailSettings::BearerMobility() const
       
   371 	{
       
   372 	if(iFlags & EBaseEmailSettingsBearerMobFlag)
       
   373 		{
       
   374 		return ETrue;
       
   375 		}
       
   376 	else
       
   377 		{
       
   378 		return EFalse;
       
   379 		}		
       
   380 	}