|
>>マクロヘルプのキーワード検索で endmacro や readonlyswtich が
>>出てこないようです。
>
> 秀丸エディタのマクロヘルプには両方ともありますよ。
ありがとうございます。秀丸メールのマクロ作成のためには、秀丸メールの
マクロヘルプと秀丸エディタのマクロヘルプを両方見ないと駄目なんですね。
ちょっと悩ましいとこです。というのは、一方のマクロヘルプを開いた状態で
もう一方のマクロヘルプを開こうとすると、最初に開いていたマクロヘルプが
閉じてしまうんです。両方開いて同時に見ようとするにはコツが要るようです。
ところでマクロの方ですが、いろいろと参考にして↓こんな感じになりました。
気になる点が2点ほどありますが、しばらくこれで様子見したいと思います。
- IsHidemaruMailMain を使っていますが、自分自身 4.50 以前の秀丸メール
を使う予定はないので敢えてこれを使ってます。
- 変換アドレスを実際に変更する際、strstr 関数を使用している関係で
単語単位での変換を行っていません。その辺で誤動作する可能性があり
ますが、自身の用途では問題にならないので、そのままにしています。
//////////////////////////////////////////////////////////////////////
// AdrTrans.mac : アドレス変換マクロ for 秀丸メール
//
// $Id$
//
// From/To/Cc ヘッダ中のメールアドレスを変換テーブルをもとにして変換
// します。自動起動時 (受信直後) は新着メール、手動起動時はカレント
// フォルダの全メールが変換の対象となります。受信直後以外の自動起動時
// は何もしません。
loaddll "tkinfo.dll";
//////////////////////////////////////////////////////////////////////
// 変換テーブル
// 変換元アドレス ($org_addr) と変換先アドレス ($new_addr) を記述します。
$org_addr[0] = "bar@k-tai.example.ne.jp"; $new_addr[0] = "xxx@example.jp";
$org_addr[1] = "org.domain"; $new_addr[1] = "new.domain";
//////////////////////////////////////////////////////////////////////
// メインルーチン
// デバッグ設定 (0: 通常、1: デバッグ)
#debug = 0;
debuginfo #debug;
// マクロ起動要因の取得
#reason = dllfunc("ReasonMacroStarted");
debuginfo "#reason = " + str(#reason);
// 自動起動 (受信直後)?
if (#reason == 3)
{
// 自動起動時:新着メールがあれば、それを対象にアドレス変換を実施
if (dllfunc("RecvMailCount") > 0)
{
call TranslateAddress 1;
}
}
// 手動起動?
if (#reason == 0)
{
// 手動起動時:本体ウィンドウ以外での処理は不可
if (!dllfunc("IsHidemaruMailMain"))
{
message "このマクロは本体ウィンドウ上で起動してください。";
goto Exit;
}
// 手動起動時:送受信中は処理を中止
if (dllfunc("IsTransmitting"))
{
#n = dllfunc("SetAutoPushTimer", 2, "ok");
message "送受信中です。アドレス変換の処理を中止します。";
goto Exit;
}
// 手動起動時:カレントフォルダの全メールを対象にアドレス変換を実施
call TranslateAddress 0;
}
// 処理終了
Exit: endmacro;
//////////////////////////////////////////////////////////////////////
// アドレス変換ルーチン
TranslateAddress:
// 引数の取得 (1: 自動起動、0: 手動起動)
##auto = ##1;
debuginfo "##auto = " + str(##auto);
// 前処理 (状態の保存など)
if (!#debug) #n = dllfunc("DisableDraw");
##thread = dllfunc("IsThreadView");
$$account = dllfuncstr("CurrentAccount");
$$folder = dllfuncstr("CurrentFolder");
// 変換テーブルのスキャン
##index = 0;
while (($org_addr[##index] != "") && ($new_addr[##index] != ""))
{
debuginfo "$org_addr[" + str(##index) + "] = " + $org_addr[##index];
debuginfo "$new_addr[" + str(##index) + "] = " + $new_addr[##index];
$org = $org_addr[##index];
$new = $new_addr[##index];
if ($org != $new)
{
// 変換対象メールの検索準備
$$find = "(\"" + $org + "\", target=from+to, word)";
if (##auto)
{
// 自動起動時:検索対象は全フォルダの新着&未読メール
#n = dllfunc("SelectFolder", dllfuncstr("Account", 0), "");
$$find = $$find + ", inmail=3, subfolder=1, flag=hot&unread";
}
else
{
// 手動起動時:検索対象はカレントフォルダの全メール
#n = dllfunc("SetThreadView", 0);
#n = dllfunc("SetMailIndex", 0);
$$find = $$find + ", inmail=0, subfolder=0";
}
// 変換対象メールの検索と置換
#n = dllfunc("SetFindPack", $$find);
while (1)
{
if (!dllfunc("FindDownInclude")) break;
// From/To/Cc ヘッダ中のメールアドレスの置換
#n = dllfunc("BeginEditMail");
call ReplaceHeader "From";
call ReplaceHeader "To";
call ReplaceHeader "Cc";
#n = dllfunc("SaveEditMail", 0, 0);
#n = dllfunc("SetViewAreaFoundBefore");
if (!dllfunc("NextPrevCustom", "", "down", "", "")) break;
}
}
##index = ##index + 1;
}
// 後処理 (状態の復帰など)
#n = dllfunc("SelectFolder", $$account, "");
#n = dllfunc("SelectFolder", $$account, $$folder);
#n = dllfunc("SetThreadView", ##thread);
#n = dllfunc("EnableDraw");
return;
ReplaceHeader:
// 引数の取得 (ヘッダ名)
$$header = $$1;
debuginfo "$$header = " + $$header;
##index = 0;
while (1)
{
$$str = dllfuncstr("CurrentHeader2", $$header, ##index);
if ($$str == "") break;
debuginfo "$$str.org = " + $$str;
while (1)
{
##ptr = strstr($$str, $org);
if (##ptr < 0) break;
$$left = leftstr($$str, ##ptr);
$$right = rightstr($$str, strlen($$str) - strlen($org) - ##ptr);
$$str = $$left + $new + $$right;
}
debuginfo "$$str.new = " + $$str;
#n = dllfunc("SetHeader", $$header, $$str, ##index);
##index = ##index + 1;
}
return;
|
|