OWLNext    7.0
Borland's Object Windows Library for the modern age
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
16namespace owl {
17
19
20 static tchar MapiLibName[] = _T("mapi32.dll");
21
22//
23// Loads the MAPI DLL.
24//
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//
58void
61{
62 // Get the document names--either directly if passed, or by parsing the paths
63 //
65 if (!docNames) {
66 // The file name must be separated by semi-colon, so parse the string for
67 // the sub-strings
68 //
70 tmpDocNames = new tchar[1024];
71 *tmpDocNames = 0;
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 //
82 GetFileTitle(nameToken, tmpName, _MAX_PATH);
83
84 // Append to string of file names (no paths)
85 //
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;
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 //
105 const auto docPathsNarrow = const_cast<LPSTR>(_W2A(docPaths));
106 const auto docNamesNarrow = const_cast<LPSTR>(_W2A(docNames));
108 reinterpret_cast<ULONG_PTR>(owner->GetHandle()),
109 const_cast<LPSTR>(";"), // delim
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//
132bool
134{
135 TProfile mailSection(_T("Mail"));
136 return mailSection.GetInt(_T("MAPI")) != 0;
137}
138
139} // OWL namespace
140/* ========================================================================== */
141
#define TRACE(message)
Definition checks.h:255
void SendDocuments(TWindow *owner, LPCTSTR paths, LPCTSTR names=0, bool asynchWork=false)
Definition mailer.cpp:59
TModuleProc5< ULONG, ULONG_PTR, LPSTR, LPSTR, LPSTR, ULONG > MAPISendDocuments
Definition mailer.h:51
bool IsMAPIAvailable() const
Returns true if the system is configured with a MAPI compliant client application installed.
Definition mailer.cpp:133
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
Definition profile.h:44
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Definition of Common Dialog abstract base class.
#define _tcscat
Definition cygwin.h:83
#define _tcstok
Definition cygwin.h:84
#define _MAX_PATH
Definition cygwin.h:97
#define _T(x)
Definition cygwin.h:51
Class definition for implementation of Mail enabling.
#define _W2A(lpw)
Definition memory.h:219
char * strnewdup(const char *s, size_t minAllocSize=0)
Definition memory.cpp:25
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
Definition of TProfile class.
Base window class TWindow definition, including HWND encapsulation.