1 #ifdef _WIN32
2 
3 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
4 //
5 // File: MAPIAppointment.cpp
6 // Description: MAPI Appointment class wrapper
7 //
8 // Copyright (C) 2005-2011, Noel Dillabough
9 //
10 // This source code is free to use and modify provided this notice remains intact and that any enhancements
11 // or bug fixes are posted to the CodeProject page hosting this class for the community to benefit.
12 //
13 // Usage: see the CodeProject article at http://www.codeproject.com/internet/CMapiEx.asp
14 //
15 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 
17 // Ported to U++ Framework by Koldo. See License.txt file
18 
19 #include "MAPIEx.h"
20 
21 /////////////////////////////////////////////////////////////
22 // MAPIAppointment
23 
MAPIAppointment()24 MAPIAppointment::MAPIAppointment() {
25 #ifdef _WIN32_WCE
26 	m_pAppointment=NULL;
27 #endif
28 }
29 
~MAPIAppointment()30 MAPIAppointment::~MAPIAppointment() {
31 	Close();
32 }
33 
34 #ifdef _WIN32_WCE
Open(MAPIEx * pMAPI,IAppointment * pAppointment)35 bool MAPIAppointment::Open(MAPIEx* pMAPI, IAppointment* pAppointment) {
36 	Close();
37 	m_pMAPI = pMAPI;
38 	m_pAppointment=pAppointment;
39 	return true;
40 }
41 
Close()42 void MAPIAppointment::Close() {
43 	RELEASE(m_pAppointment);
44 	m_pMAPI = NULL;
45 }
46 
GetPropertyString(ULONG ulProperty,String & strProperty,bool bStream)47 bool MAPIAppointment::GetPropertyString(ULONG ulProperty, String& strProperty, bool bStream) {
48 	return m_pMAPI->GetPOOM()->GetProperty(m_pAppointment,ulProperty, strProperty);
49 }
50 
SetPropertyString(ULONG ulProperty,const String & szProperty,bool bStream)51 bool MAPIAppointment::SetPropertyString(ULONG ulProperty, const String &szProperty, bool bStream) {
52 	return m_pMAPI->GetPOOM()->SetProperty(m_pAppointment,ulProperty, szProperty);
53 }
54 
55 #else
56 
GetSubject()57 String MAPIAppointment::GetSubject() {
58 	return GetPropertyString(PR_SUBJECT);
59 }
60 
GetLocation()61 String MAPIAppointment::GetLocation() {
62 	String strLocation;
63 	if(GetOutlookPropertyString(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_LOCATION, strLocation))
64 		return strLocation;
65 	return String();
66 }
67 
GetTime(ULONG property)68 Time MAPIAppointment::GetTime(ULONG property) {
69 	SYSTEMTIME st;
70 	LPSPropValue pProp;
71 	if(GetOutlookProperty(OUTLOOK_DATA2, property, pProp)) {
72 		FILETIME tmLocal;
73 		FileTimeToLocalFileTime(&pProp->Value.ft, &tmLocal);
74 		FileTimeToSystemTime(&tmLocal, &st);
75 		MAPIFreeBuffer(pProp);
76 		return MAPIEx::GetSystemTime(st);
77 	}
78 	return Null;
79 }
80 
SetSubject(const String & szSubject)81 bool MAPIAppointment::SetSubject(const String &szSubject) {
82 	return SetPropertyString(PR_SUBJECT, szSubject);
83 }
84 
SetLocation(const String & szLocation)85 bool MAPIAppointment::SetLocation(const String &szLocation) {
86 	return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_LOCATION, szLocation);
87 }
88 
SetStartTime(const Time & tm)89 bool MAPIAppointment::SetStartTime(const Time &tm) {
90 	SYSTEMTIME st;
91 	MAPIEx::SetSystemTime(st, tm);
92 	FILETIME ftStart;
93 	SystemTimeToFileTime(&st, &ftStart);
94 	return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_START, ftStart);
95 }
96 
SetEndTime(const Time & tm)97 bool MAPIAppointment::SetEndTime(const Time &tm) {
98 	SYSTEMTIME st;
99 	MAPIEx::SetSystemTime(st, tm);
100 	FILETIME ftEnd;
101 	SystemTimeToFileTime(&st, &ftEnd);
102 	return SetOutlookProperty(OUTLOOK_DATA2, OUTLOOK_APPOINTMENT_END, ftEnd);
103 }
104 
105 const GUID PSETID_Meeting = {0x6ED8DA90, 0x450B, 0x101B, {0x98, 0xDA, 0x00, 0xAA, 0x00, 0x3F, 0x13, 0x05}};
106 
107 #define LID_GLOBAL_OBJID 0x23
108 
GetMeetingUID()109 String MAPIAppointment::GetMeetingUID() {
110 	String strUID;
111 
112 	MAPINAMEID NamedID = {0};
113 	NamedID.lpguid = (LPGUID) &PSETID_Meeting;
114 	NamedID.ulKind = MNID_ID;
115 	NamedID.Kind.lID = LID_GLOBAL_OBJID;
116 	LPMAPINAMEID lpNamedID = &NamedID;
117 
118 	LPSPropTagArray lpNamedPropTags = NULL;
119 	if(m_pItem && m_pItem->GetIDsFromNames(1, &lpNamedID, 0, &lpNamedPropTags) == S_OK) {
120 		// Set our type to binary
121 		lpNamedPropTags->aulPropTag[0] = CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[0],PT_BINARY);
122 
123 		// Get the value of the property.
124 		LPSPropValue pProp;
125 		ULONG ulVal = 0;
126 		if(m_pItem->GetProps(lpNamedPropTags, 0, &ulVal, &pProp) == S_OK) {
127 			strUID = GetHexString(pProp->Value.bin);
128 			MAPIFreeBuffer(pProp);
129 		}
130 		MAPIFreeBuffer(lpNamedPropTags);
131 	}
132 	return strUID;
133 }
134 
135 #endif
136 #endif