// After changing any name field you should call this to update PR_INITIALS and PR_DISPLAY_NAME bool MAPIContact::UpdateDisplayName() { String strPrefix, strFirst, strMiddle, strLast, strGeneration, strFullName, strFileAs, strInitials; strPrefix = GetDisplayNamePrefix(); if(strPrefix.GetLength()) { strFullName = strPrefix; strFullName += ' '; } strFirst = GetName(PR_GIVEN_NAME); if(strFirst.GetLength()) { strFileAs += strFirst; strInitials += strFirst[0]; strInitials += '.'; } strMiddle = GetName(PR_MIDDLE_NAME); if(strMiddle.GetLength()) { if(strFileAs.GetLength()) strFileAs += ' '; strFileAs += strMiddle; strInitials += strMiddle[0]; strInitials += '.'; int i = 1, nLen = strMiddle.GetLength(); while(i < nLen) { if(strMiddle[i-1] == ' ') { strInitials += strMiddle[i]; strInitials += '.'; } i++; } } strLast = GetName(PR_SURNAME); if(strLast.GetLength()) { if(strFileAs.GetLength()) strFileAs += ' '; strFileAs += strLast; strInitials += strLast[0]; strInitials += '.'; } if(strFileAs.GetLength()) strFullName += strFileAs; strGeneration = GetGeneration(); if(strGeneration.GetLength()) { if(strFullName.GetLength()) strFullName += ' '; strFullName += strGeneration; } #ifdef _WIN32_WCE return SetName(strFileAs, PR_DISPLAY_NAME); #else if(!SetPropertyString(PR_INITIALS, strInitials)) return false; if(!SetName(strFullName, PR_DISPLAY_NAME)) return false; SetOutlookProperty(OUTLOOK_DATA1, OUTLOOK_FILE_AS, strFileAs); if(!SetPropertyString(PR_SUBJECT, strFileAs)) return false; return SetPropertyString(PR_NORMALIZED_SUBJECT, strFileAs); #endif }
bool MAPIContact::SetIMAddress(const String &szIMAddress) { #ifndef _WIN32_WCE return SetOutlookProperty(OUTLOOK_DATA1, OUTLOOK_IM_ADDRESS, szIMAddress); #else return false; #endif }
bool MAPIContact::SetFileAs(const String &szFileAs) { #ifdef _WIN32_WCE return SetPropertyString(PR_DISPLAY_NAME, szFileAs); #else return SetOutlookProperty(OUTLOOK_DATA1, OUTLOOK_FILE_AS, szFileAs); #endif }
bool MAPIContact::SetEmailDisplayAs(const String &szDisplayAs, int nIndex) { #ifdef _WIN32_WCE return false; #endif ULONG nID = GetOutlookEmailID(nIndex); if(!nID) return false; return SetOutlookProperty(OUTLOOK_DATA1, nID-3, szDisplayAs); }
// only supports setting SMTP Email Addresses, sets both display properties, use SetEmailDisplayAs to set the // outlook DisplayAs property to some other text. You should check that the text is a valid SMTP email address // ie [email protected] because this function will allow any string bool MAPIContact::SetEmail(const String &szEmail, int nIndex) { ULONG nID = GetOutlookEmailID(nIndex); if(!nID) return false; #ifdef _WIN32_WCE return m_pPOOM ? m_pPOOM->SetProperty(m_pContact, nID, szEmail) : false; #else if(SetOutlookProperty(OUTLOOK_DATA1, nID-1, "SMTP")) { // we set the email field and both display properties if(!SetOutlookProperty(OUTLOOK_DATA1, nID, szEmail)) return false; if(!SetOutlookProperty(OUTLOOK_DATA1, nID+1, szEmail)) return false; if(!SetOutlookProperty(OUTLOOK_DATA1, nID-3, szEmail)) return false; return true; } return false; #endif }
// special case attachment that is used by outlook for contact pictures // szPath should point to a valid JPG or PNG (others may work but only tried these) // For optimal results the image should be max 72x96 pixels but anything works AFAIK bool MAPIContact::SetPicture(const String &szPath) { #ifdef _WIN32_WCE return false; #else if(GetAttachmentCount() > 0 && !DeleteAttachment()) return false; bool bPicture = false; if(!szPath.IsEmpty()) bPicture = AddAttachment(szPath, CONTACT_PICTURE, CONTACT_PICTURE); SetOutlookProperty(MAPIContact::OUTLOOK_DATA1, MAPIContact::OUTLOOK_PICTURE_FLAG, bPicture, PT_BOOLEAN); if(szPath.IsEmpty()) return true; return bPicture; #endif }
// updates the outlook display address; call this after changing address fields bool MAPIContact::UpdateDisplayAddress(ContactAddress::AddressType nType) { #ifdef _WIN32_WCE return false; #else ContactAddress address; if(!GetAddress(address, nType)) return false; String strDisplayAddress; strDisplayAddress = Format(t_("%s\r\n%s %s %s\r\n%s"), address.m_strStreet, address.m_strCity,address.m_strStateOrProvince, address.m_strPostalCode,address.m_strCountry); ULONG ulProperty = OUTLOOK_DISPLAY_ADDRESS_HOME+(int)nType; return SetOutlookProperty(OUTLOOK_DATA1,ulProperty, strDisplayAddress); #endif }
// Sets the PR_POSTAL_ADDRESS text and checks the appropriate outlook checkbox by setting the index bool MAPIContact::SetPostalAddress(ContactAddress::AddressType nType) { #ifdef _WIN32_WCE return false; #else ContactAddress address; if(!GetAddress(address, nType)) return false; String strPostalAddress; strPostalAddress = Format(t_("%s\r\n%s %s %s\r\n%s"),address.m_strStreet, address.m_strCity, address.m_strStateOrProvince,address.m_strPostalCode,address.m_strCountry); if(!SetPropertyString(PR_POSTAL_ADDRESS, strPostalAddress)) return false; return SetOutlookProperty(OUTLOOK_DATA1, OUTLOOK_POSTAL_ADDRESS, (int)nType+1); #endif }
BOOL CMAPIAppointment::SetEndTime(SYSTEMTIME& tmEnd) { FILETIME ftEnd; SystemTimeToFileTime(&tmEnd, &ftEnd); return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_START, ftEnd); }
BOOL CMAPIAppointment::SetStartTime(SYSTEMTIME& tmStart) { FILETIME ftStart; SystemTimeToFileTime(&tmStart, &ftStart); return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_START, ftStart); }
BOOL CMAPIAppointment::SetLocation(LPCTSTR szLocation) { return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_START, szLocation); }