libgit2 requires zlib
[TortoiseGit.git] / src / crashrpt / MailMsg.h
blob6d412f96f238e225bafadb5b6a5a6408ed080ed7
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Module: MailMsg.h
4 //
5 // Desc: This class encapsulates the MAPI and CMC mail functions.
6 //
7 // Copyright (c) 2003 Michael Carruth
8 //
9 ///////////////////////////////////////////////////////////////////////////////
11 #pragma once
13 #include <xcmc.h> // CMC function defs
14 #include <mapi.h> // MAPI function defs
16 #ifndef TStrStrVector
17 // STL generates various warnings.
18 // 4100: unreferenced formal parameter
19 // 4663: C++ language change: to explicitly specialize class template...
20 // 4018: signed/unsigned mismatch
21 // 4245: conversion from <a> to <b>: signed/unsigned mismatch
22 #pragma warning(push, 3)
23 #pragma warning(disable: 4100)
24 #pragma warning(disable: 4663)
25 #pragma warning(disable: 4018)
26 #pragma warning(disable: 4245)
27 #include <vector>
28 #pragma warning(pop)
30 typedef std::pair<string,string> TStrStrPair;
31 typedef std::vector<TStrStrPair> TStrStrVector;
32 #endif // !defined TStrStrVector
35 // Define CMC entry points
37 typedef CMC_return_code (FAR PASCAL *LPCMCLOGON) \
38 (CMC_string, CMC_string, CMC_string, CMC_object_identifier, \
39 CMC_ui_id, CMC_uint16, CMC_flags, CMC_session_id FAR*, \
40 CMC_extension FAR*);
42 typedef CMC_return_code (FAR PASCAL *LPCMCSEND) \
43 (CMC_session_id, CMC_message FAR*, CMC_flags, \
44 CMC_ui_id, CMC_extension FAR*);
46 typedef CMC_return_code (FAR PASCAL *LPCMCLOGOFF) \
47 (CMC_session_id, CMC_ui_id, CMC_flags, CMC_extension FAR*);
49 typedef CMC_return_code (FAR PASCAL *LPCMCQUERY) \
50 (CMC_session_id, CMC_enum, CMC_buffer, CMC_extension FAR*);
53 ////////////////////////////// Class Definitions /////////////////////////////
55 // ===========================================================================
56 // CMailMsg
57 //
58 // See the module comment at top of file.
60 class CMailMsg
62 public:
63 CMailMsg();
64 virtual ~CMailMsg();
66 //-----------------------------------------------------------------------------
67 // SetTo
68 // Sets the Email:To address
70 // Parameters
71 // sAddress Address
72 // sName Optional name
74 // Return Values
75 // CMailMsg reference
77 // Remarks
78 // Only one To address can be set. If called more than once
79 // the last address will be used.
81 CMailMsg&
82 SetTo(
83 string sAddress,
84 string sName = _T("")
87 //-----------------------------------------------------------------------------
88 // SetCc
89 // Sets the Email:Cc address
91 // Parameters
92 // sAddress Address
93 // sName Optional name
95 // Return Values
96 // CMailMsg reference
98 // Remarks
99 // Multiple Cc addresses can be set.
101 CMailMsg&
102 SetCc(
103 string sAddress,
104 string sName = _T("")
107 //-----------------------------------------------------------------------------
108 // SetBc
109 // Sets the Email:Bcc address
111 // Parameters
112 // sAddress Address
113 // sName Optional name
115 // Return Values
116 // CMailMsg reference
118 // Remarks
119 // Multiple Bcc addresses can be set.
121 CMailMsg&
122 SetBc(
123 string sAddress,
124 string sName = _T("")
127 //-----------------------------------------------------------------------------
128 // SetFrom
129 // Sets the Email:From address
131 // Parameters
132 // sAddress Address
133 // sName Optional name
135 // Return Values
136 // CMailMsg reference
138 // Remarks
139 // Only one From address can be set. If called more than once
140 // the last address will be used.
142 CMailMsg&
143 SetFrom(
144 string sAddress,
145 string sName = _T("")
148 //-----------------------------------------------------------------------------
149 // SetSubect
150 // Sets the Email:Subject
152 // Parameters
153 // sSubject Subject
155 // Return Values
156 // CMailMsg reference
158 // Remarks
159 // none
161 CMailMsg&
162 SetSubject(
163 string sSubject
164 ) {m_sSubject = sSubject; return *this;};
166 //-----------------------------------------------------------------------------
167 // SetMessage
168 // Sets the Email message body
170 // Parameters
171 // sMessage Message body
173 // Return Values
174 // CMailMsg reference
176 // Remarks
177 // none
179 CMailMsg&
180 SetMessage(
181 string sMessage
182 ) {m_sMessage = sMessage; return *this;};
184 //-----------------------------------------------------------------------------
185 // AddAttachment
186 // Attaches a file to the email
188 // Parameters
189 // sAttachment Fully qualified file name
190 // sTitle File display name
192 // Return Values
193 // CMailMsg reference
195 // Remarks
196 // none
198 CMailMsg&
199 AddAttachment(
200 string sAttachment,
201 string sTitle = _T("")
204 //-----------------------------------------------------------------------------
205 // Send
206 // Send the email.
208 // Parameters
209 // none
211 // Return Values
212 // TRUE if successful
214 // Remarks
215 // First simple MAPI is used if unsuccessful CMC is used.
217 BOOL Send();
219 protected:
221 //-----------------------------------------------------------------------------
222 // CMCSend
223 // Send email using CMC functions.
225 // Parameters
226 // none
228 // Return Values
229 // TRUE if successful
231 // Remarks
232 // none
234 BOOL CMCSend();
236 //-----------------------------------------------------------------------------
237 // MAPISend
238 // Send email using MAPI functions.
240 // Parameters
241 // none
243 // Return Values
244 // -1: cancelled; 0: other failure; 1: success
246 // Remarks
247 // none
249 int MAPISend();
251 //-----------------------------------------------------------------------------
252 // Initialize
253 // Initialize MAPI32.dll
255 // Parameters
256 // none
258 // Return Values
259 // TRUE if successful
261 // Remarks
262 // none
264 BOOL Initialize();
266 //-----------------------------------------------------------------------------
267 // Uninitialize
268 // Uninitialize MAPI32.dll
270 // Parameters
271 // none
273 // Return Values
274 // void
276 // Remarks
277 // none
279 void Uninitialize();
282 +------------------------------------------------------------------------------
284 | Function: cResolveName()
286 | Parameters: [IN] lpszName = Name of e-mail recipient to resolve.
287 | [OUT] ppRecips = Pointer to a pointer to an lpMapiRecipDesc
289 | Purpose: Resolves an e-mail address and returns a pointer to a
290 | MapiRecipDesc structure filled with the recipient information
291 | contained in the address book.
293 | Note: ppRecips is allocated off the heap using MAPIAllocateBuffer.
294 | Any user of this method must be sure to release ppRecips when
295 | done with it using either MAPIFreeBuffer or cFreeBuffer.
296 +-------------------------------------------------------------------------------
298 int cResolveName( LHANDLE m_lhSession, const char * lpszName, lpMapiRecipDesc *ppRecip );
300 TStrStrVector m_from; // From <address,name>
301 TStrStrVector m_to; // To <address,name>
302 TStrStrVector m_cc; // Cc <address,name>
303 TStrStrVector m_bcc; // Bcc <address,name>
304 TStrStrVector m_attachments; // Attachment <file,title>
305 string m_sSubject; // EMail subject
306 string m_sMessage; // EMail message
308 HMODULE m_hMapi; // Handle to MAPI32.DLL
309 LPCMCQUERY m_lpCmcQueryConfiguration; // Cmc func pointer
310 LPCMCLOGON m_lpCmcLogon; // Cmc func pointer
311 LPCMCSEND m_lpCmcSend; // Cmc func pointer
312 LPCMCLOGOFF m_lpCmcLogoff; // Cmc func pointer
313 LPMAPILOGON m_lpMapiLogon; // Mapi func pointer
314 LPMAPISENDMAIL m_lpMapiSendMail; // Mapi func pointer
315 LPMAPILOGOFF m_lpMapiLogoff; // Mapi func pointer
316 LPMAPIRESOLVENAME m_lpMapiResolveName; // Mapi func pointer
317 LPMAPIFREEBUFFER m_lpMapiFreeBuffer; // Mapi func pointer
319 BOOL m_bReady; // MAPI is loaded