テキストへの書き込みNo.02258
アレス さん 17/10/20 09:34
 
お世話になります。アレスです。

先日教えていただいた方法とネットの情報を組み合わせて、メールのタイトルと送信
日付をテキストファイル(メールエディタ上)に落とす、マクロを書いてみたのですが、
うまく動作しません。
修正箇所を教えてください。

よろしくお願いします。

    loaddll "tkinfo.dll";

    //テキストファイル系の処理
    #txt = dllfunc("NewMail");
    // ヘッダを非表示に
    #headerView = dllfunc("HeaderView");
    #n = dllfunc("SwitchHeaderView", 0);
    gofiletop;
    beginsel;
    gofileend;
    delete;

    #n = dllfunc("SetJapaneseCodePageMode", 1);
    #mailcount = dllfunc("MailCountAll");
    if( #mailcount != dllfunc("MailCount") ) {
        message "メール一覧の「範囲」を「全体」にしてからマクロ実行してくだ
さい。";
        endmacro;
    }
    if( dllfunc("IsThreadView") != 0 ) {
        #n = dllfunc("SetThreadView", 0);
    }


    #mailindex = 0;
    while( #mailindex < #mailcount ) {
        #n = dllfunc("SetMailIndex", #mailindex);
        if( #n == 0 ) {
            message "メールの選択に失敗 index=" + str(#mailindex);
            endmacro;
        }
       
        #attachcount = dllfunc("CountCurrentHeader", "X-Attach:");
        #attachindex = 0;
        while( #attachindex < #attachcount ) {
            $attach = dllfuncstr("HomeDir") + dllfuncstr("CurrentAccount")
                    + "\\" + dllfuncstr("CurrentHeader2", "X-Attach:", #atta
chindex);
            $attachbasename = midstr( $attach, strrstr( $attach, "\\" ) + 1 );

            //テキストに書き込みたい
            $Subject = dllfuncstr("CurrentHeader", "Subject");
            $Subject = dllfuncstr("ValidateForFileName", $Subject);
            $Subject = leftstr( $Subject, 100 );
            $Subject = "\\" + $Subject;
            $d = dllfuncstr("GetMailTransmitDate");
            insert $Subject + "," + $d + "\n";
        }
        #mailindex = #mailindex + 1;
    }

[ ]
RE:02258 テキストへの書き込みNo.02262
秀まるお2 さん 17/10/20 10:54
 
 エディタ・ウィンドウを生成してそこにテキストを書き込む場合、
setactivehidemaruを使ってウィンドウを切り替えてやらないといけないです。
あと、添付ファイルについての処理は不要だし、添付ファイル用の処理の中に
insert文を書いたら添付ファイルの付いてないメールで何も処理されないです。

 とりあえず簡単に動くレベルのマクロだと以下のようになりました。
 setactivehidemaruをメール1通毎に実行すると遅いので、その辺改良すれば
もっと高速化は可能です。必要なそういう例もお返事できます。

    loaddll "tkinfo.dll";

    //テキストファイル系の処理
    #txt = dllfunc("NewMail");
    // ヘッダを非表示に
    #headerView = dllfunc("HeaderView");
    #n = dllfunc("SwitchHeaderView", 0);
    gofiletop;
    beginsel;
    gofileend;
    delete;
    #editor = hidemaruhandle(0);
    #n = dllfunc("SetMainWndTop");

    #n = dllfunc("SetJapaneseCodePageMode", 1);
    #mailcount = dllfunc("MailCountAll");
    if( #mailcount != dllfunc("MailCount") ) {
        message "メール一覧の範囲を「全体」にしてからマクロ実行してください。";
        endmacro;
    }
    if( dllfunc("IsThreadView") != 0 ) {
        #n = dllfunc("SetThreadView", 0);
    }


    #mailindex = 0;
    while( #mailindex < #mailcount ) {
        #n = dllfunc("SetMailIndex", #mailindex);
        if( #n == 0 ) {
            message "メールの選択に失敗 index=" + str(#mailindex);
            endmacro;
        }
       
        //テキストに書き込みたい
        $Subject = dllfuncstr("CurrentHeader", "Subject");
        $Subject = dllfuncstr("ValidateForFileName", $Subject);
        $Subject = leftstr( $Subject, 100 );
        $Subject = "\\" + $Subject;
        $d = dllfuncstr("GetMailTransmitDate");
        setactivehidemaru #editor;
        insert $Subject + "," + $d + "\n";
        #n = dllfunc("SetMainWndTop");

        #mailindex = #mailindex + 1;
    }
    setactivehidemaru #editor;

[ ]
RE:02262 テキストへの書き込みNo.02267
アレス さん 17/10/22 15:57
 
秀まるお2様

ありがとうございました。
実現できました。

添付ファイル付きのファイルのタイトルと名前を抽出したかったので、そのファイル
だけを対象にしていました。
このマクロの前に教えていただいたマクロと併せて、作成したフォルダに対してした
かった処理がありましたもので。

高速化は今のところ特に必要ありませんので大丈夫です。お気遣いありがとうござい
ました。


[ ]