email/imap4mtm/imapsession/src/cimapenvelope.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-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 "cimapenvelope.h"
       
    17 
       
    18 
       
    19 _LIT8(KTxtFormatAddressPlain, "%S@%S");
       
    20 const TInt KFormatCharsAddressPlain = 4; // %S%S
       
    21 
       
    22 _LIT8(KTxtFormatAddressWithName, "\"%S\" <%S@%S>");
       
    23 const TInt KFormatCharsAddressWithName = 6; // %S%S%S
       
    24 
       
    25 CImapEnvelope* CImapEnvelope::NewL()
       
    26 // static method
       
    27 // There is no non-trivial construction required, so no need for a ConstructL()
       
    28 	{
       
    29 	return new(ELeave)CImapEnvelope();
       
    30 	}
       
    31 
       
    32 CImapEnvelope::CImapEnvelope()
       
    33 	{}
       
    34 
       
    35 CImapEnvelope::~CImapEnvelope()
       
    36 	{
       
    37 	iEnvFrom.Close();
       
    38 	iEnvSender.Close();
       
    39 	iEnvReplyTo.Close();
       
    40 	iEnvTo.Close();
       
    41 	iEnvCc.Close();
       
    42 	iEnvBcc.Close();
       
    43 	}
       
    44 
       
    45 /**
       
    46 Returns the date field
       
    47 @return the date field
       
    48 */
       
    49 EXPORT_C const TDesC8& CImapEnvelope::EnvDate()
       
    50 	{
       
    51 	return iEnvDate;
       
    52 	}
       
    53 /**
       
    54 Returns the subject field
       
    55 @return the subject field
       
    56 */
       
    57 EXPORT_C const TDesC8& CImapEnvelope::EnvSubject()
       
    58 	{
       
    59 	return iEnvSubject;
       
    60 	}
       
    61 /**
       
    62 Returns the array of "from" addresses structures
       
    63 @return a reference to the array of "from" addresses structures
       
    64 */
       
    65 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvFrom()
       
    66 	{
       
    67 	return iEnvFrom;
       
    68 	}
       
    69 /**
       
    70 Returns the array of "sender" addresses structures
       
    71 @return a reference to the array of "sender" addresses structures
       
    72 */
       
    73 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvSender()
       
    74 	{
       
    75 	return iEnvSender;
       
    76 	}
       
    77 /**
       
    78 Returns the array of "reply to" addresses structures
       
    79 @return a reference to the array of "reply to" addresses structures
       
    80 */
       
    81 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvReplyTo()
       
    82 	{
       
    83 	return iEnvReplyTo;
       
    84 	}
       
    85 /**
       
    86 Returns the array of "to" addresses structures
       
    87 @return a reference to the array of "to" addresses structures
       
    88 */
       
    89 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvTo()
       
    90 	{
       
    91 	return iEnvTo;
       
    92 	}
       
    93 /**
       
    94 Returns the array of "carbon copy" addresses structures
       
    95 @return a reference to the array of "cc" addresses structures
       
    96 */
       
    97 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvCc()
       
    98 	{
       
    99 	return iEnvCc;
       
   100 	}
       
   101 /**
       
   102 Returns the array of "blind carbon copy" addresses structures
       
   103 @return a reference to the array of "bcc" addresses structures
       
   104 */
       
   105 EXPORT_C const CImapEnvelope::RArrayTAddress& CImapEnvelope::EnvBcc()
       
   106 	{
       
   107 	return iEnvBcc;
       
   108 	}
       
   109 /**
       
   110 Returns the "in reply to" field
       
   111 @return the "in reply to" field
       
   112 */
       
   113 EXPORT_C const TDesC8& CImapEnvelope::EnvInReplyTo()
       
   114 	{
       
   115 	return iEnvInReplyTo;
       
   116 	}
       
   117 /**
       
   118 Returns the "message id" field
       
   119 @return the "message id" field
       
   120 */
       
   121 EXPORT_C const TDesC8& CImapEnvelope::EnvMessageId()
       
   122 	{
       
   123 	return iEnvMessageId;
       
   124 	}
       
   125 
       
   126 /**
       
   127 Sets the value of the date field
       
   128 @param aEnvDate the date field
       
   129 */
       
   130 void CImapEnvelope::SetEnvDate(const TDesC8& aEnvDate)
       
   131 	{
       
   132 	iEnvDate.Set(aEnvDate);
       
   133 	}
       
   134 /**
       
   135 Sets the value of the subject field
       
   136 @param aEnvSubject the subject field
       
   137 */
       
   138 void CImapEnvelope::SetEnvSubject(const TDesC8& aEnvSubject)
       
   139 	{
       
   140 	iEnvSubject.Set(aEnvSubject);
       
   141 	}
       
   142 /**
       
   143 Appends an address structure to the list of from addresses
       
   144 @param aAddress the address structure that is to be added to the list of from addresses
       
   145 */
       
   146 void CImapEnvelope::AppendEnvFromL(const TAddress& aAddress)
       
   147 	{
       
   148 	iEnvFrom.AppendL(aAddress);
       
   149 	}
       
   150 /**
       
   151 Appends an address structure to the list of sender addresses
       
   152 @param aAddress the address structure that is to be added to the list of sender addresses
       
   153 */
       
   154 void CImapEnvelope::AppendEnvSenderL(const TAddress& aAddress)
       
   155 	{
       
   156 	iEnvSender.AppendL(aAddress);
       
   157 	}
       
   158 /**
       
   159 Appends an address structure to the list of "reply to" addresses
       
   160 @param aAddress the address structure that is to be added to the list of "reply to" addresses
       
   161 */
       
   162 void CImapEnvelope::AppendEnvReplyToL(const TAddress& aAddress)
       
   163 	{
       
   164 	iEnvReplyTo.AppendL(aAddress);
       
   165 	}
       
   166 /**
       
   167 Appends an address structure to the list of "to" addresses
       
   168 @param aAddress the address structure that is to be added to the list of "to" addresses
       
   169 */
       
   170 void CImapEnvelope::AppendEnvToL(const TAddress& aAddress)
       
   171 	{
       
   172 	iEnvTo.AppendL(aAddress);
       
   173 	}
       
   174 /**
       
   175 Appends an address structure to the list of "carbon copy" addresses
       
   176 @param aAddress the address structure that is to be added to the list of "cc" addresses
       
   177 */
       
   178 void CImapEnvelope::AppendEnvCcL(const TAddress& aAddress)
       
   179 	{
       
   180 	iEnvCc.AppendL(aAddress);
       
   181 	}
       
   182 /**
       
   183 Appends an address structure to the list of "blind carbon copy" addresses
       
   184 @param aAddress the address structure that is to be added to the list of "bcc" addresses
       
   185 */
       
   186 void CImapEnvelope::AppendEnvBccL(const TAddress& aAddress)
       
   187 	{
       
   188 	iEnvBcc.AppendL(aAddress);
       
   189 	}
       
   190 /**
       
   191 Sets the value of the "in reply to" field
       
   192 @param aEnvInReplyTo the "in reply to" field
       
   193 */
       
   194 void CImapEnvelope::SetEnvInReplyTo(const TDesC8& aEnvInReplyTo)
       
   195 	{
       
   196 	iEnvInReplyTo.Set(aEnvInReplyTo);
       
   197 	}
       
   198 /**
       
   199 Sets the value of the "message id" field
       
   200 @param aEnvMessageId the "message id" field
       
   201 */
       
   202 void CImapEnvelope::SetEnvMessageId(const TDesC8& aEnvMessageId)
       
   203 	{
       
   204 	iEnvMessageId.Set(aEnvMessageId);
       
   205 	}
       
   206 
       
   207 
       
   208 /**
       
   209 Sets the value of the name field
       
   210 @param aName the name field
       
   211 */
       
   212 void CImapEnvelope::TAddress::SetName(const TDesC8& aName)
       
   213 	{
       
   214 	iName.Set(aName);
       
   215 	}
       
   216 /**
       
   217 Sets the value of the routing information field.  This is known as addr-adl in RFC3501
       
   218 @param aAdl the routing information field
       
   219 */
       
   220 void CImapEnvelope::TAddress::SetAdl(const TDesC8& aAdl)
       
   221 	{
       
   222 	iAdl.Set(aAdl);
       
   223 	}
       
   224 /**
       
   225 Sets the value of the mailbox field
       
   226 @param aMailbox the mailbox field
       
   227 */
       
   228 void CImapEnvelope::TAddress::SetMailbox(const TDesC8& aMailbox)
       
   229 	{
       
   230 	iMailbox.Set(aMailbox);
       
   231 	}
       
   232 /**
       
   233 Sets the value of the host field
       
   234 @param aHost the host field
       
   235 */
       
   236 void CImapEnvelope::TAddress::SetHost(const TDesC8& aHost)
       
   237 	{
       
   238 	iHost.Set(aHost);
       
   239 	}
       
   240 
       
   241 /**
       
   242 Constructs an email address string from the constituent fields of the address.
       
   243 If a name is present, then the string will be of the form
       
   244 	"name" <mailbox@host>
       
   245 Otherwise it will be of the form
       
   246 	mailbox@host
       
   247 The "adl" (routing) field is not included in the address string.
       
   248 @return a heap string containing the email address.  Ownership of this string is transferred to the caller.
       
   249 */
       
   250 EXPORT_C HBufC16* CImapEnvelope::TAddress::CreateAddressStringL() const
       
   251 	{
       
   252 	// Each part of the address is provided as an 8-bit value,
       
   253 	// So build up the address as an 8-bit string
       
   254 	
       
   255 	HBufC8* address8 = NULL;
       
   256 	
       
   257 	if (iName.Length() == 0)
       
   258 		{
       
   259 		// Use plain address: mailbox@host
       
   260 		TInt length = KTxtFormatAddressPlain().Length() - KFormatCharsAddressPlain + iMailbox.Length() + iHost.Length();
       
   261 		
       
   262 		address8 = HBufC8::NewLC(length);
       
   263 		address8->Des().Format(KTxtFormatAddressPlain, &iMailbox, &iHost);		
       
   264 		}
       
   265 	else
       
   266 		{
       
   267 		// Use address with name: "name" <mailbox@host>
       
   268 		TInt length = KTxtFormatAddressWithName().Length() - KFormatCharsAddressWithName + iName.Length() + iMailbox.Length() + iHost.Length();
       
   269 		
       
   270 		address8 = HBufC8::NewLC(length);
       
   271 		address8->Des().Format(KTxtFormatAddressWithName, &iName, &iMailbox, &iHost);
       
   272 		}
       
   273 		
       
   274 	// Now do a single conversion up to 16 bits - by padding each byte with a zero.
       
   275 	// No need to put address16 on the cleanup stack, as there are no leaving methods after it has been created.
       
   276 	HBufC16* address16 = HBufC16::NewL(address8->Length());
       
   277 	address16->Des().Copy(*address8);
       
   278 		
       
   279 	CleanupStack::PopAndDestroy(address8);
       
   280 	
       
   281 	return address16;
       
   282 	}