File:  [mozdev] / mozptch / datamodul.pas
Revision 1.10: download - view: text, annotated - select for diffs - revision graph
Wed Mar 22 11:29:12 2006 UTC (13 years, 7 months ago) by oertel
Branches: MAIN
CVS tags: HEAD
bug fix: patching the pref.js new lines where inserted before the last line instead to be appended

(* Copyright (c) uib umwelt informatik buero gmbh (www.uib.de)
 This sourcecode is owned by uib
 and published under the Terms of the General Public License.
#*###CVS_HEAD_START###******************************************************
# $Id: datamodul.pas,v 1.10 2006/03/22 11:29:12 oertel Exp $
#
#*###EXCLUDE_CVS_LOG###*****************************************************
# History:
# ========
#
# $Log: datamodul.pas,v $
# Revision 1.10  2006/03/22 11:29:12  oertel
# bug fix: patching the pref.js new lines where inserted before the last line instead to be appended
#
# Revision 1.9  2004/10/29 14:18:18  oertel
# win ver 9.30.2
# Bugfix: hupsi: check_for_imapfolders still used sHost. Changed to sIncomingServer
#
# Revision 1.8  2004/10/09 15:49:35  oertel
# win ver 9.30.1
# suporting profiles.ini for TB >= 0.8 and FF >= 0.9
# update 1: bugfix in creating aplication data directories
#
# Revision 1.7  2004/10/08 17:17:36  oertel
# win ver 9.30.1
# suporting profiles.ini for TB >= 0.8 and FF >= 0.9
#
# Revision 1.6  2004/05/30 19:51:15  oertel
# -Linux support ready for delivery (beta)
# -New Variables for EmailAddress, ncoming and outgoing server
# -INI-Files debuged
# - new bin zip file
#
# Revision 1.4  2004/04/16 16:52:52  oertel
# src: terminated with multi language interface: (nearly)all messeges now in mozptch.msg
# www: spelling correction, multilanguage interface
# bin: new binary with message file
#
# Revision 1.3  2004/04/07 18:34:55  oertel
# src: continued with multi language interface
#
# Revision 1.2  2004/03/28 17:08:58  oertel
# src: started with multi language interface
# messages in the new file mozptch.msg
# new command line option -l <lang>
#
# Revision 1.1  2004/03/14 12:49:07  oertel
# Initial commit version 9.29
#
*)

unit datamodul;

interface

uses
  SysUtils, Classes,
  {$IFDEF MSWINDOWS}
  ExtCtrls, shell_func, VersionInfo,  ProcessViewer,
  ShlObj, Windows,  activeX, UnitFunc,
  Forms,
  {$ENDIF}
  {$IFDEF LINUX}
  QForms,
  {$ENDIF}
  QDialogs, preffile, IniFiles,
  QControls, QStdctrls, QGraphics,DateUtils,StrUtils,
  IdMessageClient, IdSMTP, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, Sockets, IdUDPBase, IdUDPClient, IdDNSResolver,xmlpatch,
  linux_func, linux_system, WSDLIntf;

type
  TDataModule1 = class(TDataModule)
    sendmail: TIdSMTP;
    TcpClient1: TTcpClient;
    TCPSocke: TIdTCPClient;
    procedure TcpSockeHostResolved(Sender: TComponent);
    procedure TcpSockeStatus(Sender: TComponent; Status: String);
    procedure DataModuleCreate(Sender: TObject);

    procedure doConfig(patchPrefs : boolean);
    function UpdatePrefs(KindOfMail : string):Boolean;
    procedure logwrapper(level : integer; str:string);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    interactive : boolean;
  end;

  procedure patchPrefFromIni(var TempPrefFile : TPrefFile;
                           inifileName:string;
                           inifileSection:string);
  function findOrCreateMozProf : string;
  function getAppdataDir: string;
  procedure writelog(logstr: widestring);
  function getMsg(key : widestring) : widestring;

const
 do_sendmail_check:Boolean = true;

 loggingToFile:Boolean = true;
 // Directory f�r prefs.js von Mozilla im Heimatverzeichnis
 (*
 MOZMAILDIR='mozmail';
 MOZMAILSUBDIR='default';
 MOZMAILSLTDIR='einstell.slt';
 MOZPROGDIR='c:\programme\mozilla';
 *)
 MOZPTCHINICONST='mozptch.ini';
 MOZPTCHMSGCONST='mozptch.msg';
{$IFDEF MSWINDOWS}
//pathseparator
 PS='\';
{$ENDIF}
{$IFDEF LINUX}
  PS='/';
{$ENDIF}


var
  DataModule1: TDataModule1;

  sHome, sUname, sTmp, sHost, sSysRoot: string;
  sReplyToAdress, sFullName : string;
  sIncomingServer, sOutgoingServer, sEmailAddress : string;
  sHelpVar1,sHelpVar2,sHelpVar3,sHelpVar4,sHelpVar5,
  sHelpVar6,sHelpVar7,sHelpVar8,sHelpVar9,sHelpVar10 : string;
  mozmaildir, mozmailsubdir, mozmailsltdir, mozprogdir :string;
  mozprofparentdir, mozprogname, mozaplication : string;
  mozaplication_internal : string;
  hostresolved, telearbeitsplatz : boolean;
  logfeil : TextFile;
  intFehler : integer;
  mozsltdir, completeMozDir, localMozAppdataDir : string;
  mozptchiniFileName, mozptchMsgFileName : string;
  verify_user_at_sendmail : boolean;
  checkuser_imap_folder, patchPrefs : boolean;
  execute_before, execute_after, copy_to_profile_from : string;
  mozptchmsg: TMeminiFile;
  mozptchmsgfile : string;
  widemozptchmsg: TWideStrings;
  syslang, logfilename : string;
  mozregpath, mozregname : string;

implementation

uses
ConfDialog, moz_rdf_edit;

{$R *.xfm}

(*####################################################################
# logging
####################################################################*)

// Logger
procedure writelog(logstr: widestring);
begin
 if not loggingToFile then exit;
 try
  append(logfeil);
  writeln(logfeil,logstr);
  //writeln(logstr);
  flush(logfeil);
  closeFile(logfeil);
 except
  on e : exception do
  begin
//   loggingToFile := false;
   showMessage(Format(getMsg('err_write_to_log'),[logfilename, e.Message]));
  end;
 end;
end;

procedure TDataModule1.logwrapper(level : integer; str:string);
begin
 if level <= 2 then writelog(str);
end;


procedure writeVerinfoToLog;
{$IFDEF MSWINDOWS}
var
  S: string;
  vi : TVersionInfoRec;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
  S := Application.ExeName;
  //vi := ReadVersionInfo(S);
  vi := GetVersionInfoRec(S);
  writelog('-----Angfang Version-Info-----');
  writelog(vi.CompanyName);
  writelog(vi.FileDescription);
  writelog(vi.FileVersion);
  writelog(vi.InternalName);
  writelog(vi.LegalCopyright);
  writelog(vi.LegalTradeMarks);
  writelog(vi.OriginalFilename);
  writelog(vi.ProductName);
  writelog(vi.ProductVersion);
  writelog(vi.Comments);
  writelog('-----Ende Version-Info-----');
{$ENDIF}
end;

(*####################################################################
# language
####################################################################*)

function getSystemLanguage : String;
{$IFDEF MSWINDOWS}
var
  Ident: Integer;
  MyLang: PChar;
const
  Size: Integer = 250;
begin
  GetMem(MyLang, Size);
  Ident:=GetSystemDefaultLangID;
  VerLanguageName(Ident, MyLang, Size);
  writelog('Long system language: '+StrPas(MyLang));
  getSystemLanguage:=copy(StrPas(MyLang),1,2);
  FreeMem(MyLang);
end;
{$ELSE}
 {$IFDEF LINUX}
begin
 //getSystemLanguage:=  SysLocale.
 getSystemLanguage:=copy(GetEnvironmentVariable('LANG'),1,2);
 writelog('Value of LANG: '+GetEnvironmentVariable('LANG'));
end;
 {$ENDIF}
{$ENDIF}

procedure chooseMessageLang;
var
 tmpLangStr : string;
begin
 tmpLangStr := AnsiLowerCase(getSystemLanguage);
 writelog('Short system language: '+tmpLangStr);
 if CompareStr(mozptchmsg.ReadString('messages'
                                 ,tmpLangStr
                                 ,'Message not found')
                                 ,'Message not found') = 0 then
 //if widemozptchmsg.IndexOfIgnoreCase(tmpLangStr) = -1 then
 begin
  syslang := 'en';
  writelog('language: '+tmpLangStr+' not found - fall back to english');
 end
 else
  syslang := tmpLangStr;
end;

function openMsgFile : boolean;
var
 msgfile: text;
 tmpstr : widestring;
begin
 try
  openMsgFile := true;
  mozptchMsgFileName := ExtractFilePath(Application.ExeName)
                           + mozptchmsgfile;
  if not FileExists(mozptchMsgFileName) then
  begin
   ShowMessage('Error: Messagefile: '+mozptchMsgFileName+
              ' not found.'
                    +' Please contact your system administrator.'
                    +' Program will be terminated.');
   application.terminate;
   exit;
  end;
  mozptchmsg := TMemIniFile.Create(mozptchMsgFileName);
  (*
  widemozptchmsg := TWideStrings.create;
  assignfile(msgfile,mozptchMsgFileName);
  reset(msgfile);
  while not eof(msgfile) do
  begin
   readln(msgfile,tmpstr);
   widemozptchmsg.Add(tmpstr);
   writeln(tmpstr);
  end;
  closefile(msgfile);
  *)
 except
  openMsgFile := false;
  ShowMessage('Error: Messagefile: '+mozptchMsgFileName+
              ' could not opened.'
                    +' Please contact your system administrator.'
                    +' Program will be terminated.');
   application.terminate;
   exit;
 end;
end;

function getMsg(key : widestring) : widestring;
var
 tmpstr : widestring;
 i : integer;
begin
 tmpstr := mozptchmsg.ReadString('messages'
                                 ,key+'_'+syslang
                                 ,'Message not found');
 (*
 i := widemozptchmsg.IndexOfIgnoreCase(key+'_'+syslang);
 if i = -1 then
  tmpstr := 'Message not found'
 else
  tmpstr := widemozptchmsg[i];
 *)
 // try it in english if message not found

 if AnsiComparestr(tmpstr,'Message not found') = 0 then
  tmpstr := mozptchmsg.ReadString('messages'
                                 ,key+'_en'
                                 ,'Message not found');
 // give key if message not found
 if AnsiComparestr(tmpstr,'Message not found') = 0 then
  tmpstr := tmpstr+' for: '+key;

 getMsg := AnsiReplaceStr(tmpstr,'\n',#10#13);
end;


(*####################################################################
# windows directorys
####################################################################*)


// Funktion wo liegt application-Data

{$IFDEF MSWINDOWS}
procedure FreePidl(pidl: PItemIDList);
var
  allocator: IMalloc;
begin
  if Succeeded(SHGetMalloc(allocator)) then
  begin
    allocator.Free(pidl);
    {$IFDEF VER100}
    allocator.Release;
    {$ENDIF}
  end;
end;

function getAppdataDir: string;
var
  pidl: PItemIDList;
  buf: array[0..MAX_PATH] of Char;
begin
  if Succeeded(SHGetSpecialFolderLocation(application.Handle, CSIDL_APPDATA, pidl)) then
  SHGetPathFromIDList(pidl, buf);
  Result := StrPas(buf);
  // The calling application is responsible for freeing the PItemIDList-pointer
  // with the Shell's IMalloc interface
  FreePIDL(pidl);
end;

{$ELSE}
 {$IFDEF LINUX}
function getAppdataDir: string;
begin
 // has to be written....
 getAppdataDir := GetEnvironmentVariable('HOME');
end;

 {$ENDIF}
{$ENDIF}

(*####################################################################
# tools to check input validty
####################################################################*)

function checkInputData : boolean;
var
 incommingConnected : boolean;
 ipnum : string;
begin
 checkInputData := true;
 incommingConnected := false;
 // Check for validty and complete input data
  if not DirectoryExists(mozprofparentdir) then
  begin
   if Sysutils.ForceDirectories(mozprofparentdir) then
   begin
    writelog(Format(getMsg('dir_created'),[mozprofparentdir]));
   end 
   else
   begin
    writelog('Failed creating directories: '+mozprofparentdir);
   end;
  end;
  if not DirectoryExists(mozprofparentdir) then
  begin
   writelog(Format(getMsg('target_dir_does_not_exist'),[mozprofparentdir]));
   ShowMessage(Format(getMsg('target_dir_does_not_exist'),[mozprofparentdir]));
   checkInputData := false;
   exit;
  end;
  writelog(Format(getMsg('target_dir_exists'),[mozprofparentdir]));

  // resolve incoming Server
  hostresolved := false;
  if sIncomingServer <> 'empty' then
  begin
   DataModule1.TcpSocke.Host := sIncomingServer;
   DataModule1.TcpSocke.Port := 110; //pop3
   try
    ipnum := DataModule1.TcpClient1.LookupHostAddr(sIncomingServer);
    writelog(sIncomingServer+' resolved as: '+ipnum);
    if ipnum <> '0.0.0.0' then
     hostresolved := true
    else
     hostresolved := false;
   except
    hostresolved := false;
   end;
   if not hostresolved then
   begin
    writelog(Format(getMsg('host_not_resolved'),[sIncomingServer]));
    showMessage(Format(getMsg('host_not_resolved'),[sIncomingServer]));
    checkInputData := false;
    halt;
    exit;
   end;
   writelog(TimeToStr(now)+Format(getMsg('host_resolved'),[sIncomingServer]));
   try
    DataModule1.TcpSocke.Port := 110; //pop3
    DataModule1.TcpSocke.connect(1000);
    incommingConnected := true;
    writelog(TimeToStr(now)+Format(getMsg('host_connected_at_port'),[sIncomingServer, '110 (pop3)']));
   except
    writelog(TimeToStr(now)+Format(getMsg('host_not_reached_at_port'),[sIncomingServer, '110 (pop3)']));
   end;
   DataModule1.TcpSocke.Disconnect;
   try
    DataModule1.TcpSocke.Port := 995; //spop3
    DataModule1.TcpSocke.connect(500);
    incommingConnected := true;
    writelog(TimeToStr(now)+ Format(getMsg('host_connected_at_port'),[sIncomingServer, '995 (spop3)']));
   except
    writelog(TimeToStr(now)+Format(getMsg('host_not_reached_at_port'),[sIncomingServer, '995 (spop3)']));
   end;
   DataModule1.TcpSocke.Disconnect;
   try
    DataModule1.TcpSocke.Port := 143; //imap2
    DataModule1.TcpSocke.connect(500);
    incommingConnected := true;
    writelog(TimeToStr(now)+Format(getMsg('host_connected_at_port'),[sIncomingServer, '143 (imap2)']));
   except
    writelog(TimeToStr(now)+Format(getMsg('host_not_reached_at_port'),[sIncomingServer, '143 (imap2)']));
   end;
   DataModule1.TcpSocke.Disconnect;
   try
    DataModule1.TcpSocke.Port := 220; //imap3
    DataModule1.TcpSocke.connect(500);
    incommingConnected := true;
    writelog(TimeToStr(now)+Format(getMsg('host_connected_at_port'),[sIncomingServer, '220 (imap3)']));
   except
    writelog(TimeToStr(now)+Format(getMsg('host_not_reached_at_port'),[sIncomingServer, '220 (imap3)']));
   end;
   DataModule1.TcpSocke.Disconnect;
   try
    DataModule1.TcpSocke.Port := 993; //simap4
    DataModule1.TcpSocke.connect(500);
    incommingConnected := true;
    writelog(TimeToStr(now)+Format(getMsg('host_connected_at_port'),[sIncomingServer, '993 (simap4)']));
   except
    writelog(TimeToStr(now)+Format(getMsg('host_not_reached_at_port'),[sIncomingServer, '993 (simap4)']));
   end;
   DataModule1.TcpSocke.Disconnect;

   if not incommingConnected then
   begin
    writelog(Format(getMsg('host_not_reached_at_any_port'),[sIncomingServer]));
    ShowMessage(Format(getMsg('host_not_reached_at_any_port'),[sIncomingServer]));
    checkInputData := false;
    exit;
   end;
  end;

  // resolve outgoing Server
  hostresolved := false;
  if sOutgoingServer <> 'empty' then
  begin
   DataModule1.TcpSocke.Host := sOutgoingServer;
   DataModule1.TcpSocke.Port := 25; //smtp
   try
    ipnum := DataModule1.TcpClient1.LookupHostAddr(sOutgoingServer);
    writelog(sOutgoingServer+' resolved as: '+ipnum);
    if ipnum <> '0.0.0.0' then
     hostresolved := true
    else
     hostresolved := false;
   except
    hostresolved := false;
   end;
   if not hostresolved then
   begin
    writelog(Format(getMsg('host_not_resolved'),[sOutgoingServer]));
    showMessage(Format(getMsg('host_not_resolved'),[sOutgoingServer]));
    checkInputData := false;
    exit;
   end;
   writelog(Format(getMsg('host_resolved'),[sOutgoingServer]));
   //writelog('Server '+sOutgoingServer+' was resolved.');
   try
    DataModule1.TcpSocke.connect(1000);
   except
    writelog(Format(getMsg('host_not_reached_at_port'),[sOutgoingServer, '25 (smtp)']));
    ShowMessage(Format(getMsg('host_not_reached_at_port'),[sOutgoingServer, '25 (smtp)']));
    checkInputData := false;
    exit;
   end;
   DataModule1.TcpSocke.Disconnect;
   writelog(Format(getMsg('host_connected_at_port'),[sOutgoingServer, '25 (smtp)']));
  end;

  (*
  if verify_user_at_sendmail then
  begin
   try
    DataModule1.sendmail.Host := sHost;
    DataModule1.sendmail.ReadTimeOut := 3000; // 3 Sekunden Timeout
    DataModule1.sendmail.Username := sUname;
    DataModule1.sendmail.Connect;
    DataModule1.sendmail.Verify(sUname);
    writelog(Format(getMsg('verify_user_success'),[sHost,sUname]));
    DataModule1.sendmail.Disconnect;
   except
    writelog(Format(getMsg('verify_user_failed'),[sUname,sHost]));
    showMessage(Format(getMsg('verify_user_failed'),[sUname,sHost]));
    checkInputData := false;
    exit;
   end;
  end
  else writelog(getMsg('verify_user_diabled'));
  *)

  if verify_user_at_sendmail then
  begin
   try
    DataModule1.sendmail.Host := sOutgoingServer;
    DataModule1.sendmail.ReadTimeOut := 3000; // 3 Sekunden Timeout
    DataModule1.sendmail.Username := sUname;
    DataModule1.sendmail.Connect(500);
    DataModule1.sendmail.Verify(sUname);
    writelog(Format(getMsg('verify_user_success'),[sOutgoingServer,sUname]));
    DataModule1.sendmail.Disconnect;
   except
    writelog(Format(getMsg('verify_user_failed'),[sUname,sOutgoingServer,mozptchiniFileName]));
    showMessage(Format(getMsg('verify_user_failed'),[sUname,sOutgoingServer,mozptchiniFileName]));
    checkInputData := false;
    exit;
   end;
  end
  else writelog(getMsg('verify_user_diabled'));

  (*

  // test ob mozilla l�uft......
  if IsFileActive('mozilla.exe') then
  begin
   writelog('Mozilla aktiv....Fragen was zu tun ist');
   if MessageBox(0, PointerAufString('Achtung: Mozilla ist aktiv'+#10#13+
              'Mindestens eine Instanz von Mozilla ist aktiv (Schnellstart ?)'+#10#13+
              'Mozilla mu� vollst�ndig beendet sein.'+#10#13+
              'Klicken Sie Ok um Mozilla durch dieses Programm zu beenden.'+#10#13+
              'Klicken Sie Abbrechen um weiter zu machen, wenn Sie Mozilla selbst beendet haben.'),
              'ACHTUNG!', MB_OKCANCEL) = IDOK then
   begin
    writelog('Mozilla wird beendet....');
    KillProcessByFileName('mozilla.exe', true);
    writelog('Mozilla sollte jetzt beendet sein....');
    sleep(500);
   end
   else
    writelog('Mozilla wird nicht (!!) automatisch beendet....');
   // wiederholungs pr�fung......
   if IsFileActive('mozilla.exe') then
   begin
    writelog('Mozilla immer noch aktiv....Programm-Abbruch');
    MessageBox(0, PointerAufString('Achtung: Mozilla ist immer noch aktiv'+#10#13+
               'Mindestens eine Instanz von Mozilla ist aktiv (Schnellstart ?)'+#10#13+
               'Mozilla mu� zur Maileinrichtung vollst�ndig beendet sein.'+#10#13+
               'Dieses Programm wird jetzt beendet.'+#10#13+
               'Falls Sie sich an die Hotline wenden, geben Sie Datei c:\tmp\maileinr.log mit'),
               'ACHTUNG!', MB_OK);
    checkInputData := false;
    exit;
   end
   else
    writelog('Mozilla nicht mehr aktiv....');
  end
  else
   writelog('Wenn dies Windowws 2000 ist, dann ist Mozilla nicht aktiv.');
*)
  checkInputData := true;
end;



(*####################################################################
# mozilla - find pref directory , manupulating the regitry.dat
####################################################################*)


// Funktionen mozilla spezifisch


 procedure killmozilla;
 begin
  {$IFDEF MSWINDOWS}
  writelog('killing '+mozprogname+'.....');
  Start(ExtractFilePath(Application.ExeName)+'\kill.exe '+mozprogname);
  {$ENDIF}
  {$IFDEF LINUX}
  writelog('killing '+mozprogname+'.....');
  linkill(mozprogname);
  {$ENDIF}
 end;

{$IFDEF MSWINDOWS}
 function startmozilla(param : string) : boolean;
 var
  commandline, option, report : String;
 begin
  commandline := MOZPROGDIR+PS+mozprogname;
  if not FileExists(MOZPROGDIR+PS+mozprogname) then
  begin
   writelog(Format(getMsg('no_mozilla_exe_found'),[mozprogname,MOZPROGDIR]));
   ShowMessage(Format(getMsg('no_mozilla_exe_found_msg'),[mozprogname,MOZPROGDIR]));
   application.Terminate;
   exit;
  end
  else
  begin
   if not Start ('"'+commandline+'" '+param)
   then
   Begin
    writelog('Error starting '+mozprogname);
    result := false;
   End
   else
   begin
    writelog(mozprogname+' started with '+param);
     result := true;
   end;
  end;
 end;
{$ENDIF}
{$IFDEF LINUX}
 function startmozilla(param : string) : boolean;
 var
  commandline, option, report : String;
 begin
  commandline := MOZPROGDIR+PS+mozprogname;
  if not FileExists(MOZPROGDIR+PS+mozprogname) then
  begin
   writelog(Format(getMsg('no_mozilla_exe_found'),[mozprogname,MOZPROGDIR]));
   ShowMessage(Format(getMsg('no_mozilla_exe_found_msg'),[mozprogname,MOZPROGDIR]));
   application.Terminate;
   exit;
  end
  else
  begin
   if not Start (commandline+' '+param)
   then
   Begin
    writelog('Error starting '+mozprogname);
    result := false;
   End
   else
   begin
    writelog(mozprogname+' started with '+param);
     result := true;
   end;
  end;
 end;
{$ENDIF}


function getMozSltDir(mozhome:string) : string;
  var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
 //FileAttrs := faReadOnly
 FileAttrs := 0;
 //FileAttrs := FileAttrs + faHidden;
 //FileAttrs := FileAttrs + faSysFile;
 //FileAttrs := FileAttrs + faVolumeID;
 FileAttrs := FileAttrs + faDirectory;
 //FileAttrs := FileAttrs + faArchive;
 //FileAttrs := FileAttrs + faAnyFile;
 if FindFirst(mozhome+PS+'*.slt', FileAttrs, sr) = 0 then
 begin
  result := sr.Name;
  sysutils.FindClose(sr);
 end
 else result := '';
end;

procedure delRegAndCreateNew;
const
{$IFDEF MSWINDOWS}
 pluginregdat='\pluginreg.dat';
 xulmufl='\xul.mfl';
{$ENDIF}
{$IFDEF LINUX}
 pluginregdat='/pluginreg.dat';
 xulmufl='/XUL.mfasl';
{$ENDIF}
var
 regdat : string;
 profini : text;
 Fehler : string;

begin
 {$IFDEF MSWINDOWS}
  regdat :='\'+mozregname;
 {$ENDIF}
 {$IFDEF LINUX}
  regdat :='/'+mozregname;
 {$ENDIF}

// evtl. alte registry.dat l�schen
 if FileExists(localMozAppdataDir+regdat) then
 begin
  writelog(getMsg('old_regystry_found_will_del'));
  sysutils.DeleteFile(localMozAppdataDir+regdat);
  writelog(getMsg('old_registry_deleted'));
 end
 else writelog(getMsg('no_old_registry_found'));

 // evtl. alte pluginreg.dat l�schen
 if FileExists(localMozAppdataDir+pluginregdat) then
 begin
  writelog(getMsg('old_pluginreg_found_will_del'));
  sysutils.DeleteFile(localMozAppdataDir+pluginregdat);
  writelog(getMsg('old_pluginreg_deleted'));
 end
 else writelog(getMsg('no_old_pluginreg_found'));

 if not FileExists(localMozAppdataDir+regdat) then
 begin
  writelog(Format(getMsg('no_old_registry_will_create'),
                          [localMozAppdataDir]));
  if mozregname = 'profiles.ini' then
  begin
   // new mode
   AssignFile(profini,localMozAppdataDir+regdat);
   rewrite(profini);
   writeln(profini,'[General]');
   writeln(profini,'StartWithLastProfile=1');
   writeln(profini,'');
   writeln(profini,'[Profile0]');
   writeln(profini,'Name=default');
   writeln(profini,'IsRelative=0');
   writeln(profini,'Path='+mozprofparentdir+PS+mozmaildir
                          +PS+mozmailsubdir+PS+mozmailsltdir);
   CloseFile(profini);
   // dateien reinkopieren z.B. user.js
   writelog('copy new default profile from '+mozprogdir+PS
             +'defaults'+PS+'profile'+'....');
   if not AllCopy(mozprogdir+PS+'defaults'+PS+'profile'+PS,
           mozprofparentdir+PS+mozmaildir+PS+mozmailsubdir+PS+mozmailsltdir,
     cpCreateEmptySubdirectories + cpRecursive,
     true,false,Fehler) then
   begin
    writelog(Format(getMsg('error_copying_files_from'),[mozprogdir+PS+'defaults'+PS+'profile'+PS]));
    exit;
   end;
   writelog(Format(getMsg('copy_from_succeed'),[mozprogdir+PS+'defaults'+PS+'profile'+PS]));
  end
  else
  begin
   //old mode
   // Are there white spaces in the path ?
   if pos(' ',mozprofparentdir+PS+mozmaildir) > 0 then
   begin
    writelog(getMsg('whitespace_in_path'));
    if (mozprofparentdir=localMozAppdatadir) then
    begin
     writelog(getMsg('start_mozilla_to_create_registry'));
     writelog(getMsg('create_profile_in_win_app_dir'));
     writelog(Format(getMsg('start_mozilla_with_1s'),[mozmailsubdir]));
     startmozilla('-CreateProfile '+mozmailsubdir);
     writelog(getMsg('creating_mozilla_registry_finished'));
    end
    else
    begin
     writelog(getMsg('no_whitespace_in_path_allowed'));
     ShowMessage(getMsg('no_whitespace_in_path_allowed'));
     exit;
     application.Terminate;
    (*
     writelog('starte mozilla um registry anzulegen  ....');
     writelog('starting mozilla with -CreateProfile "'+mozmailsubdir+' '+stmp+'"');
     startmozilla('-CreateProfile "'+mozmailsubdir+' '+stmp+'"');
     writelog('mozilla zum registry erzeugen beendet.');
     changeProfiledir(stmp+'\'+mozmailsubdir+'\'+getMozSltDir(stmp+'\'+mozmailsubdir),
            mozprofparentdir+'\'+mozmaildir+'\'+mozmailsubdir+'\'+MOZMAILSLTDIR);
    *)
    end
   end
   else
   begin
    writelog(getMsg('start_mozilla_to_create_registry'));
    writelog(Format(getMsg('start_mozilla_with_3s'),
               [mozmailsubdir, mozprofparentdir, mozmaildir]));
    startmozilla('-CreateProfile "'+mozmailsubdir+' '+mozprofparentdir+PS+mozmaildir+'"');
    writelog(getMsg('creating_mozilla_registry_finished'));
   end;
  end;

  if not FileExists(localMozAppdataDir+regdat) then
  begin
   writelog(getMsg('still_no_registry_found'));
   ShowMessage(getMsg('still_no_registry_found'));
   application.terminate;
   halt;
   abort;
   exit;
  end;
 end;
 // zufalls-namen des angelegten Directorys ermitteln
 mozsltdir := getMozSltDir(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir);
 writelog(Format(getMsg('new_profile_at'),
                  [mozprofparentdir, mozmaildir, mozmailsubdir, mozsltdir]));
 // evtl. delete old xul.mfl
 if FileExists(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS+mozsltdir
                   +xulmufl) then
 begin
  writelog(getMsg('start_del_xul_mfl'));
  sysutils.DeleteFile(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS
                          +mozsltdir+xulmufl);
  writelog(getMsg('del_xul_mfl'));
 end
 else writelog(getMsg('no_old_xul_mfl'));
end;

function findOrCreateMozProf : string;
var
 oldprofile : boolean;
 Fehler : string;
 TempPrefFile : TPrefFile;

begin
 try
  writelog(getMsg('start_findOrCreateMozProf'));
  oldprofile := true;
  if not DirectoryExists(mozprofparentdir +PS+ mozmaildir) then
  begin
   oldprofile := false;
   writelog(Format(getMsg('2s_doesnt_exist'),[mozprofparentdir, mozmaildir]));
  end
  else
  begin
   if not DirectoryExists(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir) then
   begin
    oldprofile := false;
    writelog(Format(getMsg('3s_doesnt_exist'),[mozprofparentdir, mozmaildir, mozmailsubdir]));
   end
   else
   begin
    mozsltdir := getMozSltDir(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir);
    if mozsltdir <> '' then
    begin
     if not FileExists(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS+mozsltdir+PS+'prefs.js') then
     begin
      oldprofile := false;
      writelog(Format(getMsg('no_prefjs_in'),[mozprofparentdir, mozmaildir, mozmailsubdir, mozsltdir]));
     end
     else
     begin
      writelog(Format(getMsg('profile_found_at'),
               [mozprofparentdir, mozmaildir, mozmailsubdir, mozsltdir]));
      result := mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS+mozsltdir;

      // F�hrende Leerzeilen in prefs.js l�schen....
      // deleting empty lines at the beginning of prefs.js....
      writelog(Format(getMsg('cleaning_prefjs_in'),
          [mozprofparentdir, mozmaildir, mozmailsubdir, mozsltdir]));
      TempPrefFile := TPrefFile.Create(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS+mozsltdir+PS+'prefs.js');
      TempPrefFile.UpdateFile;
      if TempPrefFile.success = false then
      begin
       writelog(Format(getMsg('error_at_cleaning_prefjs_in'),
          [mozprofparentdir, mozmaildir, mozmailsubdir, mozsltdir]));
       writelog(TempPrefFile.problem);
       exit;
      end;
      TempPrefFile.Free;
      delRegAndCreateNew;
     end
    end
    else
    begin
     oldprofile := false;
     writelog(Format(getMsg('no_slt_dir_at'),
              [mozprofparentdir, mozmaildir, mozmailsubdir]));
    end;
   end;
  end;
  if not oldprofile then
  begin
   // Profilverzeichnis erzeugen
   if not DirectoryExists(mozprofparentdir+mozmaildir) then
   begin
    System.MkDir(mozprofparentdir+PS+mozmaildir);
    writelog(Format(getMsg('2s_dir_created'), [mozprofparentdir, mozmaildir]));
   end
   else writelog(Format(getMsg('2s_dir_exists'), [mozprofparentdir, mozmaildir]));
   if not DirectoryExists(mozprofparentdir+PS+mozmaildir+PS+mozmailsubdir) then
   begin
    System.MkDir(mozprofparentdir+PS+mozmaildir+PS+mozmailsubdir);
    writelog(Format(getMsg('3s_dir_created'),
             [mozprofparentdir, mozmaildir, mozmailsubdir]));
   end
   else writelog(Format(getMsg('3s_dir_exists'),
             [mozprofparentdir, mozmaildir, mozmailsubdir]));
   if MOZMAILSLTDIR <> 'detect' then
   begin
    if not DirectoryExists(mozprofparentdir+PS+mozmaildir+PS+mozmailsubdir+PS+MOZMAILSLTDIR) then
    begin
     System.MkDir(mozprofparentdir+PS+mozmaildir+PS+mozmailsubdir+PS+MOZMAILSLTDIR);
     writelog(Format(getMsg('4s_dir_created'),
         [mozprofparentdir, mozmaildir, mozmailsubdir, MOZMAILSLTDIR]));
    end
    else writelog(Format(getMsg('4s_dir_exists'),
        [mozprofparentdir, mozmaildir, mozmailsubdir, MOZMAILSLTDIR]));
   end
   else
   begin
    //
   end; 
   delRegAndCreateNew;
   result := mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS+mozsltdir;
  end;
 except
  on E: Exception do
  begin
   result := '';
   writelog('Error in findOrCreateMozProf: '+E.Message);
   writelog(Format(getMsg('prog_term_because_of_error'),[E.Message]));
   ShowMessage(Format(getMsg('prog_term_because_of_error'),[E.Message]));
   application.terminate;
   exit;
  end;
 end;
end;


(*####################################################################
# manipulating the pref.js  - tools
####################################################################*)



function MakePrefPath(PathEntry: string): string;
var
   j, a, i : integer;
begin
   result := '';
   j := 0;
   a := 1;
   for i := 1 to Length(PathEntry)-1 do
    begin
        if PathEntry[i] = PS then
           begin
                inc(j);
                result := result + Copy(PathEntry, a , (i - a) + 1 ) + PS;
                a := i+1;
           end;
    end;
 if j <> 0 then result := result + Copy(PathEntry, a, Length(PathEntry))
 else result := PathEntry;
end;


function replaceStr(tempstr : string;toReplace:string; replaceWith:string) : string;
var
 lengthToReplace : integer;
 posToReplace : integer;
begin
 lengthToReplace := length(toReplace);
 posToReplace := ansipos(ansiuppercase(toReplace),ansiuppercase(tempstr));
 if posToReplace <> 0 then
 begin
  delete(tempstr,posToReplace,lengthToReplace);
  insert(replaceWith,tempstr,posToReplace);
 end;
 replaceStr := tempstr;
end;


function resolve_variables(tempstr : string; makepref: boolean) : string;
begin
 tempstr := replaceStr(tempstr,'%mozaplication%',mozaplication);
 tempstr := replaceStr(tempstr,'%sHost%',sHost);
 tempstr := replaceStr(tempstr,'%sUname%',sUname);
 tempstr := replaceStr(tempstr,'%replyToAdress%',sReplyToAdress);
 tempstr := replaceStr(tempstr,'%FullName%',sFullname);
 tempstr := replaceStr(tempstr,'%HelpVar1%',sHelpVar1);
 tempstr := replaceStr(tempstr,'%HelpVar2%',sHelpVar2);
 tempstr := replaceStr(tempstr,'%HelpVar3%',sHelpVar3);
 tempstr := replaceStr(tempstr,'%HelpVar4%',sHelpVar4);
 tempstr := replaceStr(tempstr,'%HelpVar5%',sHelpVar5);
 tempstr := replaceStr(tempstr,'%HelpVar6%',sHelpVar6);
 tempstr := replaceStr(tempstr,'%HelpVar7%',sHelpVar7);
 tempstr := replaceStr(tempstr,'%HelpVar8%',sHelpVar8);
 tempstr := replaceStr(tempstr,'%HelpVar9%',sHelpVar9);
 tempstr := replaceStr(tempstr,'%HelpVar10%',sHelpVar10);
 tempstr := replaceStr(tempstr,'%mozprogname%',mozprogname);
 tempstr := replaceStr(tempstr,'%EmailAddress%',sEmailAddress);
 tempstr := replaceStr(tempstr,'%IncomingServer%',sIncomingServer);
 tempstr := replaceStr(tempstr,'%OutgoingServer%',sOutgoingServer);
 tempstr := replaceStr(tempstr,'%mozprofparentdir%',mozprofparentdir);
 tempstr := replaceStr(tempstr,'%mozmaildir%',mozmaildir);
 tempstr := replaceStr(tempstr,'%mozmailsubdir%',mozmailsubdir);
 tempstr := replaceStr(tempstr,'%mozmailsltdir%',mozmailsltdir);
 if makepref then
 begin
  tempstr := replaceStr(tempstr,'%localMozAppdataDir%',MakePrefPath(localMozAppdataDir));
  tempstr := replaceStr(tempstr,'%completemozdir%',MakePrefPath(completemozdir));
  tempstr := replaceStr(tempstr,'%sHome%',MakePrefPath(sHome));
 end
 else
 begin
  tempstr := replaceStr(tempstr,'%localMozAppdataDir%',localMozAppdataDir);
  tempstr := replaceStr(tempstr,'%completemozdir%',completemozdir);
  tempstr := replaceStr(tempstr,'%sHome%',MakePrefPath(sHome));
 end;
 resolve_variables := tempstr;
end;

procedure readSectionStrings(inifile:TMemInifile;section:string;var stringlist:Tstrings);
var
 allstrings : TStrings;
 i : integer;
 insection : boolean;
begin
 insection := false;
 allstrings := TStringList.Create;
 inifile.GetStrings(allstrings);
 for i := 0 to allstrings.Count -1 do
 begin
  if pos('[',trim(allstrings[i])) = 1 then
  // we got a section header
  begin
    if pos('['+AnsiUpperCase(section)+']',trim(AnsiUpperCase(allstrings[i]))) =1 then
     // we got the rigth one
     insection := true
    else
     insection := false;  // we got a wrong one
  end
  else // no section header
  begin
   if insection then
   begin
    stringlist.Add(allstrings[i]);
   end
   else
   begin
    if pos('[',trim(allstrings[i])) = 1 then
     // we got a section header
     if pos('['+AnsiUpperCase(section)+']',trim(AnsiUpperCase(allstrings[i]))) =1 then
      // we got the rigth one
      insection := true
     else
      insection := false;  // we got a wrong one
   end;
  end;
 end;
end;


procedure patchPrefFromIni(var TempPrefFile : TPrefFile;
                           inifileName:string;
                           inifileSection:string);
var
  mozptchini: TMeminiFile;
  //TempPrefFile : TPrefFile;
  tempStrings : TStrings;
  tempstr : string;
  i : integer;
begin
 mozptchini := TMemIniFile.Create(inifileName);
 tempStrings := TStringList.Create;
 readSectionStrings(mozptchini,inifilesection,tempstrings);
 writelog(Format(getMsg('read_from_lines_read_from_file_and_section'),
              [inifileName, iniFileSection, IntToStr(tempStrings.Count)]));

 for i := 0 to tempstrings.Count-1 do
 begin
  tempstr := tempstrings[i];
  if (pos('//',trim(tempstr)) <> 1) and
     (length(tempstr) > 0) then
  begin
   writelog('preparing for prefs.js: '+tempstr);
   tempstr := resolve_variables(tempstr,true);
   if pos('mozptch_ini_variable_error',tempstr) > 0 then
   begin
    writelog('not used: '+tempstr);
   end
   else
   begin
    TempPrefFile.AddPrefLine(tempstr);
   end;
  end
  else
  begin
   //writelog('detected as comment: '+tempstr);
  end;
 end;
end;
(*####################################################################
# getting variables from mozpcth.ini - tools
####################################################################*)

function getVariableValue(name:string) : string;
var
  resultstr : string;
  howToFind : string;
  mozptchini, specialini: TMeminiFile;
  tempStrings : TStrings;
  tempstr : string;
  i : integer;
  envname : string;
  filename, section, key : string;
  feil : text;
  question : string;
begin
 resultstr := '';
 mozptchini := TMemIniFile.Create(mozptchiniFileName);
 howToFind := mozptchini.ReadString('variables',name,'error');
 if howtofind = 'error' then
 begin
  writelog(Format(getMsg('no_rule_to_find_value_of'),[name, mozptchiniFileName]));
  //ShowMessage(Format(getMsg('no_rule_to_find_value_of'),[name, mozptchiniFileName]));
  resultstr := 'mozptch_ini_variable_error';
  //getVariableValue := resolve_variables(resultstr,false);
  //writelog(Format(getMsg('got_value_for_varable_with'),
  //                                 [name, howtofind, resultstr]));
  //exit;
  // ok, let's ask for the value
  howtofind:='ask';
  writelog('trying to ask for the value...');
 end;

  if uppercase(howtofind) = 'DETECT' then
  begin
   resultstr := 'detect';
  end;
  if uppercase(howtofind) = uppercase('environment') then
  begin
   envname := mozptchini.ReadString('environment',name,'error');
   if envname = 'error' then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, envname, mozptchiniFileName]));
    ShowMessage(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, envname, mozptchiniFileName]));
    resultstr := 'mozptch_ini_variable_error';
    getVariableValue := resolve_variables(resultstr,false);
    writelog(Format(getMsg('got_value_for_varable_with'),
                                [name, howtofind, envname, resultstr]));
    exit;
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
   resultstr := ValueOfEnvVar (resolve_variables(envname,false));
   writelog(Format(getMsg('got_value_for_varable_with'),
               [name, howtofind, resolve_variables(envname,false), resultstr]));
  end;

  if uppercase(howtofind) = uppercase('localDefinedVariable') then
  begin
   resultstr := mozptchini.ReadString('localDefinedVariable',name,'mozptch_ini_variable_error');
   if resultstr = 'mozptch_ini_variable_error' then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, resultstr, mozptchiniFileName]));
    ShowMessage(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, resultstr, mozptchiniFileName]));
    exit;
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
   resultstr := resolve_variables(resultstr, false);
   writelog(Format(getMsg('got_value_for_varable_with'),
               [name, howtofind, '', resultstr]));
  end;

  if uppercase(howtofind) = 'INIFILE' then
  begin
   filename := mozptchini.ReadString('inifile-'+name,'filename','error');
   section := mozptchini.ReadString('inifile-'+name,'section','error');
   key := mozptchini.ReadString('inifile-'+name,'key','error');
   if (filename = 'error') or
      (section = 'error') or
      (key = 'error') then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind,'File: '+filename
                           +', Section: '+section
                           +', Key: '+key
            , resultstr]));
    ShowMessage(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind,'File: '+filename
                           +', Section: '+section
                           +', Key: '+key
            , resultstr]));
    resultstr := 'mozptch_ini_variable_error';
    getVariableValue := resolve_variables(resultstr,false);
    writelog(Format(getMsg('got_value_for_varable_with'),
               [name, howtofind, '', resultstr]));
    exit;
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
   specialini := TMemIniFile.Create(resolve_variables(filename,false));
   resultstr := specialini.ReadString(resolve_variables(section,false),
                                      resolve_variables(key,false),
                                      'mozptch_ini_variable_error');
   specialini.Free;
   writelog(Format(getMsg('got_value_for_varable_with'),
           [name, howtofind,'File: '+resolve_variables(filename,false)
                           +', Section: '+resolve_variables(section,false)
                           +', Key: '+resolve_variables(key,false)
            , resultstr]));
   if resultstr = 'mozptch_ini_variable_error' then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind,'File: '+resolve_variables(filename,false)
                           +', Section: '+resolve_variables(section,false)
                           +', Key: '+resolve_variables(key,false)
            , resultstr]));
    showmessage(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind,'File: '+resolve_variables(filename,false)
                           +', Section: '+resolve_variables(section,false)
                           +', Key: '+resolve_variables(key,false)
            , resultstr]));
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
  end;

  if uppercase(howtofind) = 'FILE' then
  begin
   filename := mozptchini.ReadString('file-'+name,'filename','error');
   if filename = 'error' then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, filename, mozptchiniFileName]));
    ShowMessage(Format(getMsg('value_for_varable_not_found_with'),
            [name, howtofind, filename, mozptchiniFileName]));
    resultstr := 'mozptch_ini_variable_error';
    (*
    getVariableValue := resolve_variables(resultstr,false);
    writelog(Format(getMsg('got_value_for_varable_with'),
               [name, howtofind, filename, resultstr]));
    *)
   //exit;
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
   if FileExists(resolve_variables(filename,false)) then
   begin
    assignfile(feil,resolve_variables(filename,false));
    reset(feil);
    readln(feil,resultstr);
    closefile(feil);
    writelog(Format(getMsg('got_value_for_varable_with'),
          [name, howtofind, resolve_variables(filename,false), resultstr]));
   end
   else
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
     [name, howtofind, resolve_variables(filename,false)+': Error: not found', resultstr]));
//   showmessage(Format(getMsg('value_for_varable_not_found_with'),
//    [name, howtofind, resolve_variables(filename,false)+': Error: not found', resultstr]));
    resultstr := 'mozptch_ini_variable_error';
   // ok, let's ask for the value
   howtofind:='ask';
   writelog('trying to ask for the value...');
   end;
  end;

  if uppercase(howtofind) = 'ASK' then
  begin
   question := mozptchini.ReadString('ask-'+name,'text','error');
   if question = 'error' then
   begin
    writelog(Format(getMsg('value_for_varable_not_found_with'),
     [name, howtofind, 'question: '+question, resultstr]));
    ShowMessage(Format(getMsg('value_for_varable_not_found_with'),
     [name, howtofind, 'question: '+question, resultstr]));
    resultstr := 'mozptch_ini_variable_error';
    (*
    getVariableValue := resolve_variables(resultstr,false);
    writelog('Variable '+name+' �ber '+howtofind+' gesetzt auf den wert: '+resultstr);
    *)
    exit;
   end;
  resultstr := InputBox(getMsg('please_insert'),question,'');
   writelog(Format(getMsg('got_value_for_varable_with'),
          [name, howtofind, question, resultstr]));
  end;
  getVariableValue := resolve_variables(resultstr,false);
end;

(*####################################################################
# getting mozptch.ini values for mimetypes
####################################################################*)

procedure setMimetypeEntriesFromMozptchIni;
var
  mozptchini: TMeminiFile;
  tempStrings : TStrings;
  i : integer;
  mimetype, progpath, progname, extension : string;
begin
 mozptchini := TMemIniFile.Create(mozptchiniFileName);
 tempStrings := TStringList.Create;
 mozptchini.ReadSectionValues('mimetype_helper', tempStrings);
 for i:= 0 to tempStrings.Count-1 do
 begin
  if not ((tempStrings[i] = '') or ((pos('/',tempstrings[i])=1)
                             and (pos('/',tempstrings[i])=2))) then
  begin
   if mozptchini.SectionExists('install-'+tempStrings.Names[i]) then
   begin
    mimetype := mozptchini.ReadString('install-'+tempStrings.Names[i],
                                         'mimetype','error');
    progpath := mozptchini.ReadString('install-'+tempStrings.Names[i],
                                         'progpath','error');
    progname := mozptchini.ReadString('install-'+tempStrings.Names[i],
                                         'progname','error');
    extension := mozptchini.ReadString('install-'+tempStrings.Names[i],
                                         'extension','error');
    writelog('install: mimetype: '+mimetype);
    writelog('install: progpath: '+progpath);
    writelog('install: progname: '+progname);
    writelog('install: extension: '+extension);
    if ((mimetype = 'error') or
        (progpath = 'error') or
        (progname = 'error') or
        (extension = 'error')) then
    begin
     writelog(Format(getMsg('uncomplete_or_wrong_install_information_about_application')
                        ,[tempStrings.Names[i]]));
    end
    else
    begin
     writelog(getMsg('adding_mimetype_handler'));
     addMimeHandler(mimetype,progpath,progname,extension);
     writelog(getMsg('mimetypehandler_added'));
    end;
   end;
   if mozptchini.SectionExists('deinstall-'+tempStrings.Names[i]) then
   begin
    mimetype := mozptchini.ReadString('deinstall-'+tempStrings.Names[i],
                                         'mimetype','error');
    writelog('deinstall: mimetype: '+mimetype);
    if (mimetype = 'error') then
    begin
     writelog(Format(getMsg('uncomplete_or_wrong_deinstall_information_about_application'),
                           [tempStrings.Names[i]]));
    end
    else
    begin
     writelog(getMsg('deleting_mimetypehandler'));
     delMimeHandler(mimetype);
     writelog(getMsg('mimetypehandler_deleted'));
    end;
   end;
  end;
 end;
 tempStrings.Free;
end;

(*####################################################################
# manipulating the pref.js  - content
####################################################################*)


function TDataModule1.UpdatePrefs(KindOfMail : string):Boolean;
var
   TempPrefFile : TPrefFile;
   NameOfPrefFile, TempInternetAddress : string;
   k : TextFile;
   problem : string;
   AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word;
begin
   result := false;
   //sreplyToAdress := getVariableValue('%replyToAdress%');
   //sFullName := getVariableValue('%fullname%');
   //if sFullName = '' then
   //    sFullName := sUname;
   NameOfPrefFile := completemozdir +PS+'prefs.js';
   if not FileExists(NameOfPrefFile) then
   begin
    writelog(Format(getMsg('file_does_not_exist_will_be_created'),
                              [NameOfPrefFile]));
    AssignFile(k,NameOfPrefFile);
    Rewrite(k);
    writeln(k,'# Mozilla User Preferences');
    writeln(k,'// This is a generated file!');
    CloseFile(k);
   end;
   if not FileExists(NameOfPrefFile) then
   begin
    writelog(Format(getMsg('file_does_not_exist'),[NameOfPrefFile]));
    exit;
   end;
   writelog(Format(getMsg('backing_up_file'),[NameOfPrefFile]));
   DecodeDateTime(now,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
   if not FileCopy(NameOfPrefFile,
                   NameOfPrefFile+'_'
                   +IntToStr(AYear)+'_'
                   +IntToStr(AMonth)+'_'
                   +IntToStr(ADay)+'_'
                   +IntToStr(AHour)+'_'
                   +IntToStr(AMinute),
                   true,true,problem) then
   begin
    writelog(Format(getMsg('error_backing_up_file'),[NameOfPrefFile,problem]));
    exit;
   end;
   writelog(Format(getMsg('file_backuped'), [NameOfPrefFile]));
   TempPrefFile := TPrefFile.Create(NameOfPrefFile);
   (*************************************************************************)
   ///Hier kommen die sachen die unabh�ngig von pop/imap/internet sind
   (**************************************************************************)
    patchPrefFromIni(TempPrefFile,
                           mozptchIniFileName,
                           'general_prefjs_entries');

   //// ab hier abh�ngiges von pop, imap, internet
   if KindOfMail = 'POP' then
    begin

      patchPrefFromIni(TempPrefFile,
                           mozptchIniFileName,
                           'pop_perfjs_entries');
    end;

    (* f�r IMAP ver 9.18 detlef oertel 15.6.01 *)
    if KindOfMail = 'IMAP' then
    begin
     patchPrefFromIni(TempPrefFile,
                           mozptchIniFileName,
                           'imap_prefjs_entries');


    end; // ende IMAP
     TempPrefFile.UpdateFile;
     if TempPrefFile.success = false then
     begin
      writelog(TempPrefFile.problem);
      exit;
     end;
     TempPrefFile.Free;
     result := true;
end;




procedure Tdatamodule1.doConfig(patchPrefs : boolean);
var
  Fehler : string;
  problem : string;
  AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word;
  rdffile : text;
begin
 killmozilla;
 writelog(getMsg('start_procedure_doConfig'));
 Fehler := '';

 // find old profile or create new....
{$IFDEF MSWINDOWS}
  localMozAppdataDir := getAppdataDir+PS+mozregpath;
{$ENDIF}
{$IFDEF LINUX}
  localMozAppdataDir := getAppdataDir+PS+'.'+mozregpath;
{$ENDIF}
 writelog('localMozAppdataDir is '+localMozAppdataDir);
 completeMozDir := findOrCreateMozProf;
 writelog('completeMozDir is '+completeMozDir);

 if copy_to_profile_from <> 'no' then
  if not DirectoryExists(copy_to_profile_from) then
  begin
   writelog(Format(getMsg('dir_to_copy_from_not_found'),[copy_to_profile_from]));
  end
  else
  begin
   // dateien reinkopieren z.B. user.js
   writelog('kopiere Dateien aus '+copy_to_profile_from+'....');
   if not AllCopy(copy_to_profile_from+PS,completeMozDir,
     cpCreateEmptySubdirectories + cpRecursive { Rupert R�der 3.9.2002, vorher 99 },
     true,false,Fehler) then
   begin
    writelog(Format(getMsg('error_copying_files_from'),[copy_to_profile_from]));
    exit;
   end;
   writelog(Format(getMsg('copy_from_succeed'),[copy_to_profile_from]));
  end; //copy_to_profile_from

 writelog('gibt es mimetypes.rdf.....');
 if not FileExists(completeMozDir+PS+'mimetypes.rdf') then
 begin
  writelog(getMsg('no_mimetypes_rdf_try_template'));
  if not fileExists(completeMozDir+PS+'mimetypes.tmpl') then
  begin
   AssignFile(rdffile,completeMozDir+PS+'mimetypes.tmpl');
   rewrite(rdffile);
   writeln(rdffile,'<?xml version="1.0"?>');
   writeln(rdffile,'<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"');
   writeln(rdffile,'         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">');
   writeln(rdffile,'  <RDF:Description about="urn:mimetypes">');
   writeln(rdffile,'    <NC:MIME-types resource="urn:mimetypes:root"/>');
   writeln(rdffile,'  </RDF:Description>');
   writeln(rdffile,'  <RDF:Seq about="urn:mimetypes:root">');
   writeln(rdffile,'  </RDF:Seq>');
   writeln(rdffile,'</RDF:RDF>');
   CloseFile(rdffile);
  end;
  if not FileCopy(completeMozDir+PS+'mimetypes.tmpl',
                  completeMozDir+PS+'mimetypes.rdf',
                  true,true,problem) then
  begin
   writelog(Format(getMsg('error_copying_file'),
          ['mimetypes.tmpl','mimetypes.rdf',problem]));
  end;
 end;
 writelog(Format(getMsg('exists_file'),['mimetypes.rdf']));
 if not FileExists(completeMozDir+PS+'mimetypes.rdf') then
 begin
  ShowMessage(getMsg('no_mimetypes_rdf_terminate'));
  writelog(getMsg('no_mimetypes_rdf_terminate'));
  application.terminate;
  exit;
 end
 else
 begin
  writelog(Format(getMsg('backing_up_file'),['mimetypes.rdf']));
  DecodeDateTime(now,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
  if not FileCopy(completeMozDir+PS+'mimetypes.rdf',
                  completeMozDir+PS+'mimetypes.rdf'+'_'
                  +IntToStr(AYear)+'_'
                  +IntToStr(AMonth)+'_'
                  +IntToStr(ADay)+'_'
                  +IntToStr(AHour)+'_'
                  +IntToStr(AMinute),
                  true,true,problem) then
  begin
   writelog(Format(getMsg('backing_up_file'),['mimetypes.rdf',problem]));
   exit;
  end;
  writelog(Format(getMsg('file_backuped'),['mimetypes.rdf']));
  //sysutils.DeleteFile(completeMozDir+'\mimetypes.rdf');
  writelog(Format(getMsg('patching_file'),['mimetypes.rdf']));
  openRdfFile(completeMozDir+PS+'mimetypes.rdf');
  setMimetypeEntriesFromMozptchIni;
  saveRdfFile(completeMozDir+PS+'mimetypes.rdf');
  writelog(Format(getMsg('file_saved'),['mimetypes.rdf']));
 end;


 if patchPrefs then
 begin
  writelog(getMsg('patching_prefsjs_with_mode_IMAP'));
  //Pref-Dateien �ndern
  if UpdatePrefs('IMAP') = False then
  begin
   writelog(getMsg('patching_file_failed'));
  end;
  writelog(getMsg('prefsjs_patched'));
 end;

 (*####################################################################
 # Start special hupsi custom part
 ####################################################################*)

 // Here special code for hupsi
 if checkuser_imap_folder then
 begin
  //INBOX anlegen  �ber homes-share wg. GROSSBUCHSTABEN (home-share wandelt 8.3 nach klein)
  if not FileExists('\\'+sIncomingServer+PS+sUname+'\INBOX') then
  begin
   if FileCopy('p:\mail\empty.mbx', '\\'+sIncomingServer+PS+sUname+'\INBOX',
               true,true,Fehler)= False then
   begin
    writelog('Datei empty.mbx konnte nicht nach '+sHome+'\INBOX kopiert werden. '
          +Fehler); exit;
   end
   else
   begin
    writelog(sHome+'\INBOX angelegt');
    {$IFDEF MSWINDOWS}
     intFehler := FileSetAttr('\\'+sIncomingServer+PS+sUname+'\INBOX',0);
    {$ELSE}
     {$IFDEF LINUX}
     {$ENDIF}
    {$ENDIF}
    if intFehler <> 0 then
    begin
     writelog('Setzen der Schreibrechte f�r INBOX schlug fehl: FehlerNr: '+IntTostr(intFehler));
    end;
    writelog('Attribute f�r INBOX gesetzt.');
   end;
  end
  else writelog(sHome+'\INBOX existiert. OK');

  // ./imap anlegen
  if not DirectoryExists(sHome+'\.imap') then
  begin
   try
    mkDir (sHome+'\.imap');
    writelog(sHome+'\.imap angelegt');
   except
    writelog('Verzeichnis '+sHome+'\.imap konnte nicht angelegt werden.');
   end;
  end;
  if DirectoryExists(sHome+'\.imap') then
  begin
   if not FileExists('\\'+sIncomingServer+PS+sUname+'\.imap\gesendet') then
    if FileCopy('p:\mail\empty.mbx', '\\'+sIncomingServer+'\'+sUname+'\.imap\gesendet',
                true,true,Fehler)= False then
    begin
     writelog('Datei empty.mbx konnte nicht nach \\'+sIncomingServer+'\'+sUname+'\.imap\gesendet kopiert werden. '
           +Fehler);
    end
    else
    begin
     writelog('\\'+sIncomingServer+'\'+sUname+'\.imap\gesendet angelegt');
     {$IFDEF MSWINDOWS}
      intFehler := FileSetAttr('\\'+sIncomingServer+'\'+sUname+'\.imap\gesendet',0);
     {$ELSE}
      {$IFDEF LINUX}
      {$ENDIF}
     {$ENDIF}
     if intFehler <> 0 then
     begin
      writelog('Setzen der Schreibrechte f�r .imap\gesendet schlug fehl: FehlerNr: '+IntTostr(intFehler));
     end;
     writelog('Attribute f�r .imap\gesendet gesetzt.');
    end;
   if not FileExists('\\'+sIncomingServer+'\'+sUname+'\.imap\Entwuerfe') then
    if FileCopy('p:\mail\empty.mbx', '\\'+sIncomingServer+PS+sUname+'\.imap\Entwuerfe',
                true,true,Fehler)= False then
    begin
     writelog('Datei empty.mbx konnte nicht nach \\'+sIncomingServer+'\'+sUname+'\.imap\Entwuerfe kopiert werden. '
           +Fehler); exit;
    end
    else
    begin
     writelog('\\'+sIncomingServer+'\'+sUname+'\.imap\Entwuerfe angelegt');
     {$IFDEF MSWINDOWS}
      intFehler := FileSetAttr('\\'+sIncomingServer+'\'+sUname+'\.imap\Entwuerfe',0);
     {$ELSE}
      {$IFDEF LINUX}
      {$ENDIF}
     {$ENDIF}
     if intFehler <> 0 then
     begin
      writelog('Setzen der Schreibrechte f�r .imap\Entwuerfe schlug fehl: FehlerNr: '+IntTostr(intFehler));
     end;
     writelog('Attribute f�r .imap\Entwuerfe gesetzt.');
    end;

   if not FileExists('\\'+sIncomingServer+'\'+sUname+'\.imap\Vorlagen') then
    if FileCopy('p:\mail\empty.mbx', '\\'+sIncomingServer+'\'+sUname+'\.imap\Vorlagen',
                true,true,Fehler)= False then
    begin
     writelog('Datei empty.mbx konnte nicht nach \\'+sIncomingServer+'\'+sUname+'\.imap\Vorlagen kopiert werden. '
           +Fehler); exit;
    end
    else
    begin
     writelog('\\'+sIncomingServer+'\'+sUname+'\.imap\Vorlagen angelegt');
     {$IFDEF MSWINDOWS}
      intFehler := FileSetAttr('\\'+sIncomingServer+'\'+sUname+'\.imap\Vorlagen',0);
     {$ELSE}
      {$IFDEF LINUX}
      {$ENDIF}
     {$ENDIF}
     if intFehler <> 0 then
     begin
      writelog('Setzen der Schreibrechte f�r .imap\Vorlagen schlug fehl: FehlerNr: '+IntTostr(intFehler));
      exit;
     end;
     writelog('Attribute f�r .imap\Vorlagen gesetzt.');
    end;

  end; // ende in /.imap

  if not DirectoryExists(completemozdir+'\ich_bin_imapuser') then
  begin
   try
    mkDir (completemozdir+'\ich_bin_imapuser');
    writelog(completemozdir+'\ich_bin_imapuser angelegt');
   except
    writelog('Verzeichnis '+completemozdir+'\ich_bin_imapuser konnte nicht angelegt werden.'); exit;
   end;
  end
  else writelog(completemozdir+'\ich_bin_imapuser   existiert. OK');

 end; // end of checkuser_imap_folder
 end; //  function TFNetsptch.Intranetmail : Integer;


(*####################################################################
# End special custom part
####################################################################*)



procedure TDataModule1.TcpSockeHostResolved(Sender: TComponent);
begin
 hostresolved := true;
 writelog('hostresolved');
end;

procedure TDataModule1.TcpSockeStatus(Sender: TComponent;
  Status: String);
begin
 writelog(Status);
end;


procedure startConfiguration;
var
   i : integer;
begin
  writelog('start with Configuration...');
  if execute_before <> 'no' then
  begin
   begin
    writelog('Starting: '+execute_before);
    start(execute_before);
   end;
  end
  else writelog('Nothig to start before...');

  if true then // historic :-||
  begin
   if not FileExists(completemozdir + PS+'prefs.js') then
   begin
    DataModule1.doConfig(true);
    writelog(getMsg('no_prefjs'));
   end
   else
   begin
    writelog(Format(getMsg('profile_found_at'),[completemozdir,'','','']));
    if DataModule1.interactive then
    begin
     if patchPrefs then
     begin
      if messageDlg(Format(getMsg('ask_for_confirmation_with_patch'),
                            [mozaplication,completemozdir]),
                             mtConfirmation, mbYesNo,0,mbYes) = mrNo then
//      Messagebox(0, PChar(Format(getMsg('ask_for_confirmation_with_patch'),
//                            [mozaplication,completemozdir])),
//             ' Warnung', MB_TASKMODAL + MB_YESNO + MB_DEFBUTTON1) = IDNO then
      begin
       writelog(getMsg('user_informed_about_existing_prefjs'));
       writelog(getMsg('existing_prefsjs_should_be_pachted'));
       writelog(getMsg('terminated_by_user'));
      end
      else
      begin
       writelog(getMsg('user_informed_about_existing_prefjs'));
       writelog(getMsg('existing_prefsjs_should_be_pachted'));
       writelog(getMsg('start_confirmed_by_user'));

       // Here we go ....
       DataModule1.doConfig(true);
       writelog('End of startConfiguration');
      end;
     end
     else
     begin
      if messageDlg(Format(getMsg('ask_for_confirmation_without_patch'),
                            [mozaplication,completemozdir]),
                            mtConfirmation,mbYesNo,0,mbYes)=mrNo then
//      if Messagebox(0, PChar(Format(getMsg('ask_for_confirmation_without_patch'),
//                            [mozaplication,completemozdir])),
//                 ' Warnung', MB_TASKMODAL + MB_YESNO + MB_DEFBUTTON1) = IDNO then
      begin
       writelog(getMsg('user_informed_about_existing_prefjs'));
       writelog(getMsg('existing_prefsjs_should_not_be_pachted'));
       writelog(getMsg('terminated_by_user'));
      end
      else
      begin
       writelog(getMsg('user_informed_about_existing_prefjs'));
       writelog(getMsg('existing_prefsjs_should_not_be_pachted'));
       writelog(getMsg('start_confirmed_by_user'));
       // Here we go.....
       DataModule1.doConfig(false);
       writelog('End of startConfiguration');
      end;
     end;
    end
    else DataModule1.doConfig(true);
   end;
  end;
  if execute_after <> 'no' then
  begin
   writelog('Starting: '+execute_after);
   start(execute_after);
  end
  else writelog('Nothig to start after...');
end;

procedure TDataModule1.DataModuleCreate(Sender: TObject);
var
  InstallNewMail: boolean;
  mozptchini : TMeminiFile;
  i : integer;
  tmpString : String;
begin
 interactive := true;  // normaly interactive
 // Callback f�r xmlpatch logger
 setLogProcedure(logwrapper);
  // Logfile er�ffnen
  {$IFDEF MSWINDOWS}
  if DirectoryExists('c:\tmp') then
   logfilename := 'c:\tmp\maileinr.log'
  else
   logfilename := GetEnvironmentVariable('TEMP')+'\maileinr.log';
  {$ENDIF}
  {$IFDEF LINUX}
   if not DirectoryExists(GetEnvironmentVariable('HOME')+'/.mozptch') then
    CreateDir(GetEnvironmentVariable('HOME')+'/.mozptch');
   logfilename := GetEnvironmentVariable('HOME')+'/.mozptch/mozptch.log';
  {$ENDIF}
  assignfile(logfeil,logfilename);
  rewrite(logfeil);
  writeln(logfeil,  'Started at '+DateTimeTostr(now));
  closeFile(logfeil);
  writeVerinfoToLog;
  mozptchmsgfile := MOZPTCHMSGCONST;
  OpenMsgFile;
  chooseMessageLang;
  writelog(getMsg('langselect'));

 // mozptchini als parameter �bergeben ?
 mozptchiniFileName := ExtractFilePath(Application.ExeName)
                           + MOZPTCHINICONST;
 if (paramcount > 0)then
 begin
  for i := 1 to paramcount do
  begin
   if (paramstr(i) = '-f') then
    if paramcount > i then
    begin
     mozptchiniFileName := paramstr(i+1);
    end;
   // -s parameter for silent (non interactive)
   if (paramstr(i) = '-s') then interactive := false;
   // -m parameter for manual messagefile selection
   if (paramstr(i) = '-m') then
    if paramcount > i then
    begin
     mozptchmsgfile := paramstr(i+1);
     writelog('messagefile set by -m Argument to :'+mozptchmsgfile);
     OpenMsgFile;
    end;
   // -l parameter for manual language selection
   if (paramstr(i) = '-l') then
    if paramcount > i then
    begin
     syslang := paramstr(i+1);
     writelog('Language set by -l Argument to :'+syslang);
    end;
  end;
 end;
 if not FileExists(mozptchiniFileName) then
 begin
  ShowMessage(Format(getMsg('err_conf_not_found'),[mozptchiniFileName, logfilename]));
  writelog(Format(getMsg('err_conf_not_found'),[mozptchiniFileName, logfilename]));
  application.terminate;
  exit;
 end
 else
 begin
  writelog(Format(getMsg('conf_file_name'),[mozptchiniFileName]));
 end;

  InstallNewMail := True;
  // get generalconfiguration
  mozptchini := TMemIniFile.Create(mozptchiniFileName);
  tmpString := mozptchini.ReadString('general_configuration',
                          'verify_user_at_sendmail','false');
  if  (LowerCase(tmpString) = 'true') or (tmpString = '1') then
   verify_user_at_sendmail := true
  else
   verify_user_at_sendmail := false;
  writelog('verify_user_at_sendmail : '
                  +BoolToStr(verify_user_at_sendmail,true));
  tmpString := mozptchini.ReadString('general_configuration',
                          'checkuser_imap_folder','false');
  if  (LowerCase(tmpString) = 'true') or (tmpString = '1') then
   checkuser_imap_folder := true
  else
   checkuser_imap_folder := false;
  writelog('checkuser_imap_folder : '
                  +BoolToStr(checkuser_imap_folder,true));
  execute_before :=
      mozptchini.ReadString('general_configuration',
                            'execute_before','no');
  writelog('execute_before : '+execute_before);
  execute_after :=
      mozptchini.ReadString('general_configuration',
                            'execute_after','no');
  writelog('execute_after : '+execute_after);
  copy_to_profile_from :=
      mozptchini.ReadString('general_configuration',
                            'copy_to_profile_from','no');
  writelog('copy_to_profile_from : '+copy_to_profile_from);

  // variable init
  (*
  sHome := ValueOfEnvVar ('HOME');
  sUname := ValueOfEnvVar ('UNAME');
  sHost := ValueOfEnvVar('HOST');
  *)
  sTmp := ValueOfEnvVar ('TEMP');
  mozaplication := getVariableValue('%mozaplication%');
  mozaplication_internal := getVariableValue('%mozaplication_internal%');
  mozregname := getVariableValue('%mozregname%');
  mozregpath := getVariableValue('%mozregpath%');

  sHelpVar1 := getVariableValue('%HelpVar1%');
  sHelpVar2 := getVariableValue('%HelpVar2%');
  sUname := getVariableValue('%sUname%');
  sEmailAddress := getVariableValue('%EmailAddress%');
  sHelpVar3 := getVariableValue('%HelpVar3%');
  sHelpVar4 := getVariableValue('%HelpVar4%');
  sHost := getVariableValue('%sHost%');
  sIncomingServer := getVariableValue('%IncomingServer%');
  sOutgoingServer := getVariableValue('%OutgoingServer%');
  sHelpVar5 := getVariableValue('%HelpVar5%');
  sHelpVar6 := getVariableValue('%HelpVar6%');
  sHome := getVariableValue('%sHome%');
  sHelpVar7 := getVariableValue('%HelpVar7%');
  sHelpVar8 := getVariableValue('%HelpVar8%');
  sreplyToAdress := getVariableValue('%replyToAdress%');
  if sreplyToAdress = '' then
      sreplyToAdress := sEmailAddress;
  sFullName := getVariableValue('%fullname%');
  if sFullName = '' then
      sFullName := sUname;
  {$IFDEF MSWINDOWS}
   localMozAppdataDir := getAppdataDir+PS+mozregpath;
  {$ENDIF}
  {$IFDEF LINUX}
   localMozAppdataDir := getAppdataDir+'/.'+mozregpath;
  {$ENDIF}
  writelog('localMozAppdataDir is '+localMozAppdataDir);
  sHelpVar9 := getVariableValue('%HelpVar9%');
  sHelpVar10 := getVariableValue('%HelpVar10%');
  //sreplyToAdress := getVariableValue('%replyToAdress%');
  // where to find mozilla.exe
  mozprogdir := getVariableValue('%mozprogdir%');
  // name of 'mozilla.exe'
  mozprogname := getVariableValue('%mozprogname%');
  //a mozilla profile path is
  // eg. n:/home/user1/mozmail/default/einstell.slt/prefs.js
  //where n:/home/user1 is
  mozprofparentdir := getVariableValue('%mozprofparentdir%');
  //where mozmail is
  mozmaildir := getVariableValue('%mozmaildir%');
  // where default is
  mozmailsubdir := getVariableValue('%mozmailsubdir%');
  // where einstell.slt is
  mozmailsltdir := getVariableValue('%mozmailsltdir%');

  // special code for customer hupsi
  if ('1' = ValueOfEnvVar ('TELEPC')) then telearbeitsplatz := true
  else telearbeitsplatz := false;
  if telearbeitsplatz then
   writelog('Dies ist ein Telearbeitsplatz')
  else
   writelog('Variable TELEPC nicht gesetzt');

  if sIncomingServer = 'bonifax' then
  begin
   writelog('host bonifax gefunden....');
   if messageDlg('Achtung: '+#10#13+
              'Hostname bonifax wurde gefunden.'+#10#13+
              'Am boniplatz ist der mailserver zumeist die hlh2.'+#10#13+
              'Klicken Sie Ok um Host auf hlh2 umzusetzen.'+#10#13+
              'Klicken Sie Abbrechen um host auf bonifax zu belassen.',
               mtConfirmation, mbOKCancel,0,mbOk) = mrOk then
//   if MessageBox(0, PointerAufString('Achtung: '+#10#13+
//              'Hostname bonifax wurde gefunden.'+#10#13+
//              'Am boniplatz ist der mailserver zumeist die hlh2.'+#10#13+
//              'Klicken Sie Ok um Host auf hlh2 umzusetzen.'+#10#13+
//              'Klicken Sie Abbrechen um host auf bonifax zu belassen.'),
//              'ACHTUNG!', MB_OKCANCEL) = IDOK then
   begin
    sIncomingServer := 'hlh2';
    sOutgoingServer := 'hlh2';
    writelog('host von bonifax auf hlh2 gesetzt....');
   end;
  end;
  // end of special code for customer hupsi

  writelog('sHome = '+sHome);
  writelog('sUname = '+sUname);
  writelog('sHost = '+sHost);
  writelog('sTmp = '+sTmp);
  sSysRoot := ValueOfEnvVar ('SYSTEMROOT');
  writelog('sSysRoot = '+sSysRoot);
  writelog('interactive = '+BoolToStr(interactive,true));


  if checkInputData then
  begin
   completemozdir := mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir+PS
                     + getMozSltDir(mozprofparentdir +PS+ mozmaildir+PS+mozmailsubdir);
   if interactive then
   begin
     if InstallNewMail = false then Application.Terminate;
     FUser := TFUser.Create(Application);
     FUser.Caption := Format(getMsg('title_info_about_configuration'),[mozaplication]);
     FUser.CheckBoxPatchPrefs.Caption := getMsg('CheckBoxPatchPrefs_caption');
     FUser.TextViewer1.text := Format(getMsg('main_user_info_about_configuration')
                                      ,[mozaplication,sUname,sHome,mozprofparentdir,
                                        mozaplication,mozaplication,mozaplication]);
     if FUser.ShowModal = mrCancel then
     begin
      writelog('Programm terminated by user after Info');
      FUser.Release;
      Application.Terminate;
      exit;
     end;
     if FUser.CheckBoxPatchPrefs.Checked then
      patchPrefs := true
     else
      patchPrefs := false;
     FUser.Release;
     writelog('showed main user info');
   end
   else
   begin
    //startConfiguration;
   end;
   startConfiguration;
   if interactive then
     MessageDlg(Format(getMsg('process_finished'),[mozaplication]), mtInformation, [mbOK], 0);
  end
  else
  begin
   writelog(getMsg('err_Input_data_not_complete_or_wrong'));
   exit;
  end;

end;

end.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>