1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
9 * last change: $Author:$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
44 #define INCL_DOSERRORS
48 // OOo uses popen() to start us, so we cannot show PM dialogs.
49 // log message to disk.
50 void logMessage( char* msg
)
53 CHAR szApplicationName
[_MAX_PATH
];
54 CHAR szDrive
[_MAX_PATH
];
55 CHAR szDir
[_MAX_PATH
];
56 CHAR szFileName
[_MAX_PATH
];
57 CHAR szExt
[_MAX_PATH
];
62 // get executable fullpath
63 DosGetInfoBlocks(NULL
, &pib
);
64 DosQueryModuleName(pib
->pib_hmte
, sizeof(szApplicationName
), szApplicationName
);
65 _splitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
67 _makepath( szApplicationName
, szDrive
, szDir
, szFileName
, (".LOG") );
68 log
= fopen( szApplicationName
, "a");
72 localTime
= localtime( &timeOfDay
);
73 fprintf( log
, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
74 localTime
->tm_year
+1900, localTime
->tm_mon
+1, localTime
->tm_mday
,
75 localTime
->tm_hour
, localTime
->tm_min
, localTime
->tm_sec
, msg
);
79 // dump comand line arguments
80 void dumpArgs( int argc
, char *argv
[] )
84 logMessage( "Start of command line arguments dump:");
85 for( i
=0; i
<argc
; i
++)
90 * The intended use of this tool is to pass the argument to
91 * the default mail handler.
93 int main(int argc
, char *argv
[] )
96 RESULTCODES result
= {0};
97 char szAppFromINI
[_MAX_PATH
];
98 char szDirFromINI
[_MAX_PATH
];
100 char szFail
[ _MAX_PATH
];
104 BOOL bMailClient
= FALSE
;
109 logMessage( "Usage: senddoc --mailclient <client> --attach <uri>");
110 dumpArgs( argc
, argv
);
114 // check configuration
115 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
116 "DefaultMailExe", "",
117 szAppFromINI
, sizeof(szAppFromINI
));
118 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
119 "DefaultMailWorkingDir", "",
120 szDirFromINI
, sizeof(szDirFromINI
));
121 if (*szAppFromINI
== 0 || *szDirFromINI
== 0)
123 logMessage( "Unable to find default mail handler in USER.INI; exiting.");
124 dumpArgs( argc
, argv
);
128 // get default parameter list, at leat -compose is required
129 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
130 "DefaultMailParameters", "",
131 szCmdLine
, sizeof(szCmdLine
));
132 if (strstr( szCmdLine
, "-compose") == 0)
133 strcat( szCmdLine
, " -compose"); // add if missing!
135 // parse cmdline arguments
136 for( i
=1; i
<argc
; i
++)
138 if (!strcmp( argv
[i
], "--mailclient")) {
139 // we support only Thunderbird/Mozilla command line options, check exe name
140 if (strstr( argv
[i
+1], "thunderbird") == 0
141 && strstr( argv
[i
+1], "mozilla") == 0
142 && strstr( argv
[i
+1], "seamonkey") == 0)
144 logMessage( "Only Thunderbird/Mozilla is currently supported. Exiting.");
145 dumpArgs( argc
, argv
);
151 } else if (!strcmp( argv
[i
], "--attach")) {
152 strcat( szCmdLine
, " attachment=file://");
153 strcat( szCmdLine
, argv
[i
+1]);
156 // ignore other options (BTW currently none)
158 if (bMailClient
== FALSE
)
160 logMessage( "No mail client specified. Exiting.");
161 dumpArgs( argc
, argv
);
165 // change default directory
166 _chdir( szDirFromINI
);
168 // start default handler
170 CHAR szObjBuf
[CCHMAXPATH
];
172 SData
.Length
= sizeof(STARTDATA
);
173 SData
.Related
= SSF_RELATED_INDEPENDENT
;
174 SData
.FgBg
= (1) ? SSF_FGBG_FORE
: SSF_FGBG_BACK
;
175 SData
.TraceOpt
= SSF_TRACEOPT_NONE
;
177 SData
.PgmTitle
= (PSZ
)szAppFromINI
;
179 SData
.PgmName
= (PSZ
)szAppFromINI
;
180 SData
.PgmInputs
= (PSZ
)szCmdLine
;
183 SData
.Environment
= 0;
184 SData
.InheritOpt
= SSF_INHERTOPT_PARENT
;
185 SData
.SessionType
= SSF_TYPE_PM
;
189 SData
.PgmControl
= SSF_CONTROL_VISIBLE
;
193 SData
.InitXSize
= 200;
194 SData
.InitYSize
= 140;
196 SData
.ObjectBuffer
= szFail
;
197 SData
.ObjectBuffLen
= (ULONG
)sizeof(szFail
);
199 rc
= DosStartSession( &SData
, &ulSID
, &pid
);
200 // show error dialog in case of problems
201 if (rc
!= NO_ERROR
&& rc
!= ERROR_SMG_START_IN_BACKGROUND
) {
202 char szMessage
[ _MAX_PATH
*2];
203 sprintf( szMessage
, "Execution failed! rc: %d, failing module:%s", rc
, szFail
);
204 logMessage( szMessage
);
205 dumpArgs( argc
, argv
);