1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <stdlib.h> 29*cdf0e10cSrcweir #include <stdio.h> 30*cdf0e10cSrcweir #include <string.h> 31*cdf0e10cSrcweir #include <unistd.h> 32*cdf0e10cSrcweir #include <process.h> 33*cdf0e10cSrcweir #include <time.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #define INCL_DOS 36*cdf0e10cSrcweir #define INCL_DOSERRORS 37*cdf0e10cSrcweir #define INCL_PM 38*cdf0e10cSrcweir #include <os2.h> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir // OOo uses popen() to start us, so we cannot show PM dialogs. 41*cdf0e10cSrcweir // log message to disk. 42*cdf0e10cSrcweir void logMessage( char* msg) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir PPIB pib; 45*cdf0e10cSrcweir CHAR szApplicationName[_MAX_PATH]; 46*cdf0e10cSrcweir CHAR szDrive[_MAX_PATH]; 47*cdf0e10cSrcweir CHAR szDir[_MAX_PATH]; 48*cdf0e10cSrcweir CHAR szFileName[_MAX_PATH]; 49*cdf0e10cSrcweir CHAR szExt[_MAX_PATH]; 50*cdf0e10cSrcweir FILE* log; 51*cdf0e10cSrcweir time_t timeOfDay; 52*cdf0e10cSrcweir struct tm* localTime; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // get executable fullpath 55*cdf0e10cSrcweir DosGetInfoBlocks(NULL, &pib); 56*cdf0e10cSrcweir DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName); 57*cdf0e10cSrcweir _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt ); 58*cdf0e10cSrcweir // log name 59*cdf0e10cSrcweir _makepath( szApplicationName, szDrive, szDir, szFileName, (".LOG") ); 60*cdf0e10cSrcweir log = fopen( szApplicationName, "a"); 61*cdf0e10cSrcweir if (!log) 62*cdf0e10cSrcweir return; 63*cdf0e10cSrcweir time( &timeOfDay); 64*cdf0e10cSrcweir localTime = localtime( &timeOfDay); 65*cdf0e10cSrcweir fprintf( log, "%04d/%02d/%02d %02d:%02d:%02d %s\n", 66*cdf0e10cSrcweir localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, 67*cdf0e10cSrcweir localTime->tm_hour, localTime->tm_min, localTime->tm_sec, msg); 68*cdf0e10cSrcweir fclose( log); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // dump comand line arguments 72*cdf0e10cSrcweir void dumpArgs( int argc, char *argv[] ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir int i; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir logMessage( "Start of command line arguments dump:"); 77*cdf0e10cSrcweir for( i=0; i<argc; i++) 78*cdf0e10cSrcweir logMessage( argv[i]); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /* 82*cdf0e10cSrcweir * The intended use of this tool is to pass the argument to 83*cdf0e10cSrcweir * the default mail handler. 84*cdf0e10cSrcweir */ 85*cdf0e10cSrcweir int main(int argc, char *argv[] ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir APIRET rc; 88*cdf0e10cSrcweir RESULTCODES result = {0}; 89*cdf0e10cSrcweir char szAppFromINI[_MAX_PATH]; 90*cdf0e10cSrcweir char szDirFromINI[_MAX_PATH]; 91*cdf0e10cSrcweir char szCmdLine[1024]; 92*cdf0e10cSrcweir char szFail[ _MAX_PATH]; 93*cdf0e10cSrcweir ULONG ulSID; 94*cdf0e10cSrcweir PID pid; 95*cdf0e10cSrcweir int i; 96*cdf0e10cSrcweir BOOL bMailClient = FALSE; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // check parameters 99*cdf0e10cSrcweir if (argc < 5) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir logMessage( "Usage: senddoc --mailclient <client> --attach <uri>"); 102*cdf0e10cSrcweir dumpArgs( argc, argv); 103*cdf0e10cSrcweir return -1; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // check configuration 107*cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 108*cdf0e10cSrcweir "DefaultMailExe", "", 109*cdf0e10cSrcweir szAppFromINI, sizeof(szAppFromINI)); 110*cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 111*cdf0e10cSrcweir "DefaultMailWorkingDir", "", 112*cdf0e10cSrcweir szDirFromINI, sizeof(szDirFromINI)); 113*cdf0e10cSrcweir if (*szAppFromINI == 0 || *szDirFromINI == 0) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir logMessage( "Unable to find default mail handler in USER.INI; exiting."); 116*cdf0e10cSrcweir dumpArgs( argc, argv); 117*cdf0e10cSrcweir return -1; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // get default parameter list, at leat -compose is required 121*cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 122*cdf0e10cSrcweir "DefaultMailParameters", "", 123*cdf0e10cSrcweir szCmdLine, sizeof(szCmdLine)); 124*cdf0e10cSrcweir if (strstr( szCmdLine, "-compose") == 0) 125*cdf0e10cSrcweir strcat( szCmdLine, " -compose"); // add if missing! 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // parse cmdline arguments 128*cdf0e10cSrcweir for( i=1; i<argc; i++) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if (!strcmp( argv[i], "--mailclient")) { 131*cdf0e10cSrcweir // we support only Thunderbird/Mozilla command line options, check exe name 132*cdf0e10cSrcweir if (strstr( argv[i+1], "thunderbird") == 0 133*cdf0e10cSrcweir && strstr( argv[i+1], "mozilla") == 0 134*cdf0e10cSrcweir && strstr( argv[i+1], "seamonkey") == 0) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir logMessage( "Only Thunderbird/Mozilla is currently supported. Exiting."); 137*cdf0e10cSrcweir dumpArgs( argc, argv); 138*cdf0e10cSrcweir return -1; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir // mail client found 141*cdf0e10cSrcweir bMailClient = TRUE; 142*cdf0e10cSrcweir i++; 143*cdf0e10cSrcweir } else if (!strcmp( argv[i], "--attach")) { 144*cdf0e10cSrcweir strcat( szCmdLine, " attachment=file://"); 145*cdf0e10cSrcweir strcat( szCmdLine, argv[i+1]); 146*cdf0e10cSrcweir i++; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir // ignore other options (BTW currently none) 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir if (bMailClient == FALSE) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir logMessage( "No mail client specified. Exiting."); 153*cdf0e10cSrcweir dumpArgs( argc, argv); 154*cdf0e10cSrcweir return -1; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // change default directory 158*cdf0e10cSrcweir _chdir( szDirFromINI); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // start default handler 161*cdf0e10cSrcweir STARTDATA SData; 162*cdf0e10cSrcweir CHAR szObjBuf[CCHMAXPATH]; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir SData.Length = sizeof(STARTDATA); 165*cdf0e10cSrcweir SData.Related = SSF_RELATED_INDEPENDENT; 166*cdf0e10cSrcweir SData.FgBg = (1) ? SSF_FGBG_FORE : SSF_FGBG_BACK; 167*cdf0e10cSrcweir SData.TraceOpt = SSF_TRACEOPT_NONE; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir SData.PgmTitle = (PSZ)szAppFromINI; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir SData.PgmName = (PSZ)szAppFromINI; 172*cdf0e10cSrcweir SData.PgmInputs = (PSZ)szCmdLine; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir SData.TermQ = NULL; 175*cdf0e10cSrcweir SData.Environment = 0; 176*cdf0e10cSrcweir SData.InheritOpt = SSF_INHERTOPT_PARENT; 177*cdf0e10cSrcweir SData.SessionType = SSF_TYPE_PM; 178*cdf0e10cSrcweir SData.IconFile = 0; 179*cdf0e10cSrcweir SData.PgmHandle = 0; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir SData.PgmControl = SSF_CONTROL_VISIBLE; 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir SData.InitXPos = 30; 184*cdf0e10cSrcweir SData.InitYPos = 40; 185*cdf0e10cSrcweir SData.InitXSize = 200; 186*cdf0e10cSrcweir SData.InitYSize = 140; 187*cdf0e10cSrcweir SData.Reserved = 0; 188*cdf0e10cSrcweir SData.ObjectBuffer = szFail; 189*cdf0e10cSrcweir SData.ObjectBuffLen = (ULONG)sizeof(szFail); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir rc = DosStartSession( &SData, &ulSID, &pid); 192*cdf0e10cSrcweir // show error dialog in case of problems 193*cdf0e10cSrcweir if (rc != NO_ERROR && rc != ERROR_SMG_START_IN_BACKGROUND) { 194*cdf0e10cSrcweir char szMessage[ _MAX_PATH*2]; 195*cdf0e10cSrcweir sprintf( szMessage, "Execution failed! rc: %d, failing module:%s", rc, szFail); 196*cdf0e10cSrcweir logMessage( szMessage); 197*cdf0e10cSrcweir dumpArgs( argc, argv); 198*cdf0e10cSrcweir return -1; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // ok 202*cdf0e10cSrcweir return 0; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205