【ツールの概要】
・Thunderbirdというメーラー(フリー版あり)の「オプション」からいじれる「about:config」という設定を変更する。
・「about:config」は以下のような「prefs.js」というJavascriptファイルになっているので、追記する。
・おそらく推奨ではないので、自己責任で実行してください!(あくまでPowershellのお勉強としてお願いします)
・Thunderbird起動中の編集は無意味。また、編集後、起動時に読み取られ、設定がダブった場合は最後の行のみ反映される(順序が整理される)。さらに、デフォルト値の場合、削除される。
・ログインしてるユーザのプロファイル中の「about:config(prefs.js)」をいじる。全部いじる。
【環境(使っている環境)】
・Windows10
・Powershell ver5.1
・Thunderbird v78.4.0
【ソース(CallPS1.bat、呼び出し用bat)】
@echo off cd /d %~dp0 SET PSFile=ChangeThunderBirdPrefs.ps1 SET ThunderbirdApplicationName="thunderbird.exe" echo 処理を開始します。 echo. REM Thunderbird 実行確認。実行してたら終了。 tasklist | find %ThunderbirdApplicationName% if %ERRORLEVEL% == 0 ( echo Thunderbird が実行中です。Thunderbird を終了し、再度実行してください。 echo. exit /b ) REM ps1ファイル存在確認。存在してなかったら終了。 if not exist %PSFile% ( echo ChangeThunderBirdPrefs.ps1をこのファイルと同じ階層に置いて再度実行してください。 echo. exit /b ) REM ps1ファイル実行。 powershell -ExecutionPolicy RemoteSigned .\%PSFile% if %ERRORLEVEL% == 1 ( echo 処理に失敗しました。 echo. exit /b ) echo 処理が正常終了しました。 echo. pause
【ソース(ChangeThunderBirdPrefs.ps1、特定ファイルへの追記処理他もろもろ)】
$ErrorActionPreference = "Stop" # prefs.jsは既定通りインストールしていれば下記のような場所にあります。「~default」フォルダは複数ある可能性もあり。 # $env:APPDATA + "\Thunderbird\Profiles\XXXXXXX.default\prefs.js"; # ということでProfilesフォルダをまず取得 $ProfilesFoldersPath=$env:APPDATA + "\Thunderbird\Profiles"; # Profilesフォルダ内のフォルダコレクションを取得したいので、Get-ChildItem。 try{ [System.IO.DirectoryInfo[]] $dirs = Get-ChildItem $ProfilesFoldersPath -Directory; } catch [Exception] { Write-Output ("実行アカウントの既定のフォルダにThunderbirdプロファイルフォルダがありませんでした。"); throw; # code 1 return. } try{ foreach($dir in $dirs){ # 処理するProfilesフォルダ内のフォルダ名をコンソールに表示 Write-Output ('対象フォルダ :' + $dir.FullName); $targetJSFile=$dir.FullName + "\prefs.js"; Write-Output ("対象ファイル :" + $targetJSFile); # prefs.jsの存在チェック if((Test-Path $targetJSFile) -eq $false){ Write-Output ("変更用ファイルが存在しませんでした。thunderbirdを起動し、手動で設定してください。 `r`n" + $targetJSFile); continue; } Write-Output ("ファイルが存在しました。処理を続行します。"); # 追記処理。最後の行だけ設定として生きるよ、thunderbird起動時にきれいになるよ、ということを説明。 # if any same keys exists, only last row parameter is enable.(when thunderbird application executed.) # and... new line , line feed not exiting is no probrem.(thunderbird application is formating the file, after read.) Write-Output ("user_pref(`"security.tls.version.min`", 1);") | Add-Content -Encoding utf8 $targetJSFile; } } catch [Exception] { Write-Output ("設定ファイルの書込み時に何らかのエラーが発生しました。thunderbirdを起動し、手動で設定してください。"); throw; # code 1 return. } Write-Output ("設定追記処理終了しました。"); return 0;
【説明】
・追記している「"user_pref(`"security.tls.version.min`", 1);"」という文字列は、TLSの下限バージョンを1.1まで引き下げるというものです。
(デフォルトでは1.3-1.2までしか使えない)
・batを実行します。batはps1ファイルをRemoteSignedで実行させます。
・batではThunderbirdが実行中かについてプロセスを見て判断します。あったら終了。
あとはps1ファイルが無かったりエラーだったらその旨表示して終了。
・ps1の方では、Profilesフォルダの中に複数のプロファイルがある可能性があるので、全部に処理するためforeach(雑)。
・test-pathでチェックしてるので、try-catchでcatchに行くときは書き込めなかったとき等なので、その場合は処理自体中断し終了。
(1行目でErrorActionPreferenceをStopに設定しているため、このようなエラー時には継続しません。)
【総評】
それぞれの行でやってることが明確に判るよう意識しています。
Thunderbirdがベキ等性を保証してくれるので(絶対そのためじゃないけど)、
何度実行して延々とprefs.jsに追記しても、たぶん、Thunderbirdが実行時に1行にしてくれます!(そのうち仕様が変わる可能性あり)
結構即席で作ったので、try-catchの当たりなどは工夫し甲斐が残ったりしてそうですね。