1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
36 #define INCL_DOSERRORS
40 // OOo uses popen() to start us, so we cannot show PM dialogs.
41 // log message to disk.
42 void logMessage( char* msg
)
45 CHAR szApplicationName
[_MAX_PATH
];
46 CHAR szDrive
[_MAX_PATH
];
47 CHAR szDir
[_MAX_PATH
];
48 CHAR szFileName
[_MAX_PATH
];
49 CHAR szExt
[_MAX_PATH
];
54 // get executable fullpath
55 DosGetInfoBlocks(NULL
, &pib
);
56 DosQueryModuleName(pib
->pib_hmte
, sizeof(szApplicationName
), szApplicationName
);
57 _splitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
59 _makepath( szApplicationName
, szDrive
, szDir
, szFileName
, (".LOG") );
60 log
= fopen( szApplicationName
, "a");
64 localTime
= localtime( &timeOfDay
);
65 fprintf( log
, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
66 localTime
->tm_year
+1900, localTime
->tm_mon
+1, localTime
->tm_mday
,
67 localTime
->tm_hour
, localTime
->tm_min
, localTime
->tm_sec
, msg
);
71 // dump comand line arguments
72 void dumpArgs( int argc
, char *argv
[] )
76 logMessage( "Start of command line arguments dump:");
77 for( i
=0; i
<argc
; i
++)
82 * The intended use of this tool is to pass the argument to
83 * the default mail handler.
85 int main(int argc
, char *argv
[] )
88 RESULTCODES result
= {0};
89 char szAppFromINI
[_MAX_PATH
];
90 char szDirFromINI
[_MAX_PATH
];
92 char szFail
[ _MAX_PATH
];
96 BOOL bMailClient
= FALSE
;
101 logMessage( "Usage: senddoc --mailclient <client> --attach <uri>");
102 dumpArgs( argc
, argv
);
106 // check configuration
107 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
108 "DefaultMailExe", "",
109 szAppFromINI
, sizeof(szAppFromINI
));
110 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
111 "DefaultMailWorkingDir", "",
112 szDirFromINI
, sizeof(szDirFromINI
));
113 if (*szAppFromINI
== 0 || *szDirFromINI
== 0)
115 logMessage( "Unable to find default mail handler in USER.INI; exiting.");
116 dumpArgs( argc
, argv
);
120 // get default parameter list, at leat -compose is required
121 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
122 "DefaultMailParameters", "",
123 szCmdLine
, sizeof(szCmdLine
));
124 if (strstr( szCmdLine
, "-compose") == 0)
125 strcat( szCmdLine
, " -compose"); // add if missing!
127 // parse cmdline arguments
128 for( i
=1; i
<argc
; i
++)
130 if (!strcmp( argv
[i
], "--mailclient")) {
131 // we support only Thunderbird/Mozilla command line options, check exe name
132 if (strstr( argv
[i
+1], "thunderbird") == 0
133 && strstr( argv
[i
+1], "mozilla") == 0
134 && strstr( argv
[i
+1], "seamonkey") == 0)
136 logMessage( "Only Thunderbird/Mozilla is currently supported. Exiting.");
137 dumpArgs( argc
, argv
);
143 } else if (!strcmp( argv
[i
], "--attach")) {
144 strcat( szCmdLine
, " attachment=file://");
145 strcat( szCmdLine
, argv
[i
+1]);
148 // ignore other options (BTW currently none)
150 if (bMailClient
== FALSE
)
152 logMessage( "No mail client specified. Exiting.");
153 dumpArgs( argc
, argv
);
157 // change default directory
158 _chdir( szDirFromINI
);
160 // start default handler
162 CHAR szObjBuf
[CCHMAXPATH
];
164 SData
.Length
= sizeof(STARTDATA
);
165 SData
.Related
= SSF_RELATED_INDEPENDENT
;
166 SData
.FgBg
= (1) ? SSF_FGBG_FORE
: SSF_FGBG_BACK
;
167 SData
.TraceOpt
= SSF_TRACEOPT_NONE
;
169 SData
.PgmTitle
= (PSZ
)szAppFromINI
;
171 SData
.PgmName
= (PSZ
)szAppFromINI
;
172 SData
.PgmInputs
= (PSZ
)szCmdLine
;
175 SData
.Environment
= 0;
176 SData
.InheritOpt
= SSF_INHERTOPT_PARENT
;
177 SData
.SessionType
= SSF_TYPE_PM
;
181 SData
.PgmControl
= SSF_CONTROL_VISIBLE
;
185 SData
.InitXSize
= 200;
186 SData
.InitYSize
= 140;
188 SData
.ObjectBuffer
= szFail
;
189 SData
.ObjectBuffLen
= (ULONG
)sizeof(szFail
);
191 rc
= DosStartSession( &SData
, &ulSID
, &pid
);
192 // show error dialog in case of problems
193 if (rc
!= NO_ERROR
&& rc
!= ERROR_SMG_START_IN_BACKGROUND
) {
194 char szMessage
[ _MAX_PATH
*2];
195 sprintf( szMessage
, "Execution failed! rc: %d, failing module:%s", rc
, szFail
);
196 logMessage( szMessage
);
197 dumpArgs( argc
, argv
);