OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
mailer.cpp
Go to the documentation of this file.
1
//----------------------------------------------------------------------------
2
// ObjectWindows
3
// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4
//
5
/// \file
6
/// Implementation of class TMailer which provides Mail enabling.
7
//----------------------------------------------------------------------------
8
#include <
owl/pch.h
>
9
10
#include <
owl/window.h
>
11
#include <
owl/mailer.h
>
12
#include <
owl/profile.h
>
13
#include <stdio.h>
14
#include <
owl/commdial.h
>
15
16
namespace
owl
{
17
18
OWL_DIAGINFO
;
19
20
static
tchar
MapiLibName[] =
_T
(
"mapi32.dll"
);
21
22
//
23
// Loads the MAPI DLL.
24
//
25
TMailer::TMailer
()
26
:
27
TModule
(MapiLibName, true, true, false),
// shouldLoad, mustLoad and !addToList
28
MAPISendDocuments
(*this,
"MAPISendDocuments"
)
29
{
30
}
31
32
//
33
// owner
34
// The owning window that is using the mailer. Is used to parent mail UI
35
// windows
36
//
37
// paths
38
// Pointer to string containg the files to send. The files must have a
39
// fully qualified path and filename. The string could have multiple
40
// files separated by a semicolon ';'. The filenames may be long filenames.
41
//
42
// names
43
//
44
// asynchWork
45
// If true, the message submission will be made from a separate thread
46
// other than the thread where the SendMail was called. With this flag,
47
// the function returns immediately after the working thread has been
48
// created. If false, the call is synchronous and it wll return when the
49
// message is submitted to the messaging subsystem.
50
//
51
// Purpose:
52
// This function is called by apps to send files to a mail recipient. The
53
// attachments can be of any size. The underlying messaging system will ask
54
// for credentials of the recipients. When the send note is displayed, other
55
// options could be added or modified. Also at that time other type of
56
// attachments can be added (i.e. OLE objects).
57
//
58
void
59
TMailer::SendDocuments
(
TWindow
* owner, LPCTSTR docPaths,
60
LPCTSTR docNames,
bool
asynchWork)
61
{
62
// Get the document names--either directly if passed, or by parsing the paths
63
//
64
LPTSTR tmpDocNames = 0;
65
if
(!docNames) {
66
// The file name must be separated by semi-colon, so parse the string for
67
// the sub-strings
68
//
69
LPTSTR tmpPaths =
strnewdup
(docPaths);
70
tmpDocNames =
new
tchar
[1024];
71
*tmpDocNames = 0;
72
LPTSTR nameToken =
_tcstok
(tmpPaths,
_T
(
";\n"
));
73
while
(nameToken) {
74
// Strip leading blanks from name
75
//
76
while
(*nameToken ==
_T
(
' '
))
77
nameToken++;
78
79
// Get the file name (long file names are supported) from the path
80
//
81
tchar
tmpName[
_MAX_PATH
];
82
GetFileTitle(nameToken, tmpName,
_MAX_PATH
);
83
84
// Append to string of file names (no paths)
85
//
86
_tcscat
(tmpDocNames, tmpName);
87
_tcscat
(tmpDocNames,
_T
(
";"
));
88
89
// Get the next sub-string in the files string
90
//
91
nameToken =
_tcstok
(
nullptr
,
_T
(
";\n"
));
92
}
93
delete
[] tmpPaths;
94
docNames = tmpDocNames;
95
}
96
97
// Call MAPI to send the document. This function always prompts with a
98
// dialog box so that the user can provide recipients and other sending
99
// options. The function tries to etablish a session from the messaging
100
// system's shared session. If no shared session exists, it prompts for
101
// logon information to establish a session. Before the function return,
102
// it closes the session.
103
//
104
_USES_CONVERSION
;
105
const
auto
docPathsNarrow =
const_cast<
LPSTR
>
(
_W2A
(docPaths));
106
const
auto
docNamesNarrow =
const_cast<
LPSTR
>
(
_W2A
(docNames));
107
ULONG err =
MAPISendDocuments
(
108
reinterpret_cast<
ULONG_PTR
>
(owner->
GetHandle
()),
109
const_cast<
LPSTR
>
(
";"
),
// delim
110
docPathsNarrow,
111
docNamesNarrow,
112
asynchWork ? 1 : 0
// TODO: This parameter is documented as reserved; eliminate use.
113
);
114
115
if
(err)
116
{
117
TRACE
(
_T
(
"TMailer::SendDocuments failed. Error: "
) << err);
118
// TODO: A problem was encountered; throw exception.
119
}
120
121
// Delete the temp names string if we new'd one here
122
//
123
delete
[] tmpDocNames;
124
}
125
126
127
//
128
/// Returns true if the system is configured with a MAPI compliant client
129
/// application installed.
130
/// \note Verifies the [Mail] section of WIN.INI.
131
//
132
bool
133
TMailer::IsMAPIAvailable
()
const
134
{
135
TProfile
mailSection(
_T
(
"Mail"
));
136
return
mailSection.
GetInt
(
_T
(
"MAPI"
)) != 0;
137
}
138
139
}
// OWL namespace
140
/* ========================================================================== */
141
TRACE
#define TRACE(message)
Definition
checks.h:255
owl::TMailer::TMailer
TMailer()
Definition
mailer.cpp:25
owl::TMailer::SendDocuments
void SendDocuments(TWindow *owner, LPCTSTR paths, LPCTSTR names=0, bool asynchWork=false)
Definition
mailer.cpp:59
owl::TMailer::MAPISendDocuments
TModuleProc5< ULONG, ULONG_PTR, LPSTR, LPSTR, LPSTR, ULONG > MAPISendDocuments
Definition
mailer.h:51
owl::TMailer::IsMAPIAvailable
bool IsMAPIAvailable() const
Returns true if the system is configured with a MAPI compliant client application installed.
Definition
mailer.cpp:133
owl::TProfile
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
Definition
profile.h:44
owl::TProfile::GetInt
int GetInt(LPCTSTR key, int defaultInt=0)
Looks up and returns the integer value associated with the given string, key.
Definition
profile.cpp:86
owl::TWindow
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition
window.h:414
owl::TWindow::GetHandle
HWND GetHandle() const
Returns the handle of the window.
Definition
window.h:2020
commdial.h
Definition of Common Dialog abstract base class.
_tcscat
#define _tcscat
Definition
cygwin.h:83
_tcstok
#define _tcstok
Definition
cygwin.h:84
_MAX_PATH
#define _MAX_PATH
Definition
cygwin.h:97
_T
#define _T(x)
Definition
cygwin.h:51
owl::TModule::TModule
TModule(const tstring &name, bool shouldLoad=true, bool mustLoad=true, bool addToList=true)
Constructs a TModule object that is used as an alias for a DLL.
Definition
module.cpp:308
pch.h
mailer.h
Class definition for implementation of Mail enabling.
_W2A
#define _W2A(lpw)
Definition
memory.h:219
strnewdup
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition
memory.cpp:25
_USES_CONVERSION
#define _USES_CONVERSION
Definition
memory.h:217
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::tchar
char tchar
Definition
defs.h:77
owl::OWL_DIAGINFO
OWL_DIAGINFO
Definition
animctrl.cpp:14
profile.h
Definition of TProfile class.
window.h
Base window class TWindow definition, including HWND encapsulation.
source
owlcore
mailer.cpp
Generated by
1.18.0