添付ファイル圧縮-パスワード別便通知マクNo.00574
k さん 19/11/01 11:44
 
添付ファイルをパスワード付きzipを利用させていただいています。
そこで、パスワードを通知する用のメール本文で、アドレス帳の名前+様になってい
るところを送信する用の添付ファイル付きのメールの数行を引っ張ってくることはで
きないでしょうか?

例えば、1行目:〇〇株式会社 2行目:〇〇部 3行目:〇〇様

お力添えいただきますようお願い致します。




[ ]
RE:00574 添付ファイル圧縮-パスワード別No.00575
秀まるお さん 19/11/01 16:58
 
 具体的な雰囲気がよく分からないのですが、元メールの本文の先頭3行程度をその
まま入れて、その後ろに区切り線を入れるようにしてみたら、以下のようになりまし
た。

 $body = gettext( ... ) としてる所で行数が適当に指定できます。
 insert $body + .... としてる所をいじればもっと好きなように出来ると思います。


----------------------------------------------------------------------------
-------------------
// 添付ファイル圧縮-7zip-パスワード別便通知.mac by 斉藤秀夫
// 2019.02.24
// 7-zipのダウンロード先:  http://sevenzip.sourceforge.jp/
//
// 2019.03.08 Version 1.1 署名も付けるようにした。乱数発生用のメッセージ表示
回数を少し減らした。

    //パスワード付きにする場合はここにパスワードを設定しておく。
    //パスワード無しにするなら""を代入する。
    //パスワードを毎回入力したい場合は $password = "*"としておく。
    //パスワードの中には空白は入れないでください。
    //受信したメールの添付ファイルを圧縮する場合についてはパスワードの指定は
効きません。常にパスワード無しで圧縮されます。
    //
    // 例:
    //  $password = "";         ... パスワード無し
    //  $password = "pass";     ... パスワードを"pass"にする。
    //  $password = "*";        ... パスワードを毎回入力する。
    //  #passwordlength = 10;   ... パスワードを自動生成。長さ指定。
    #passwordlength = 6;

    loaddll "tkinfo.dll";
    $7zip = "C:\\Program files\\7-Zip\\7z.exe";
    if( ! existfile( $7zip ) ) {
        $7zip = "C:\\Program files (x86)\\7-Zip\\7z.exe";
        if( ! existfile( $7zip ) ) {
            message "7-Zipのプログラム用ファイルが見つかりません。7-Zipをイ
ンストールしてください。\n\n" +
                    "7-Zipは、C:\\Program files\\7-Zip またはC:\\Program fil
es (x86)\\7-Zip にインストールされてる必要があります。";
            endmacro;
        }
    }
    openreg "CURRENTUSER", "Software\\Hidemaruo\\TuruKame\\Config";
    $home = getregstr( "HomeDir" );
    closereg;
    $account = dllfuncstr("CurrentAccount");
    if( dllfunc("IsTuruKameMain") ) {
        message "このマクロは送信するメール専用です。";
        endmacro;
    }

    if( dllfunc("MailType") == 3 || readonly ) {
        message "受信したメールの添付ファイル・圧縮は、このマクロでは出来ま
せん。";
        endmacro;
    }
    if( dllfuncstr("CurrentHeader", "To" ) == "" ) {
        message "宛先がまだ指定されてません。このマクロは宛先/件名を入力した
後に実行してください。";
        endmacro;
    }
    if( dllfuncstr("CurrentHeader", "Subject" ) == "" ) {
        message "件名がまだ指定されてません。このマクロは宛先/件名を入力した
後に実行してください。";
        endmacro;
    }
    #cAttach = 0;
    while(1) {
        $aAttach[#cAttach] = dllfuncstr("CurrentHeader2", "X-Attach"
                                       , #cAttach );
        if( $aAttach[#cAttach] == "" ) break;
        #cAttach = #cAttach + 1;
    }
    if( #cAttach == 0 ) {
        message "添付ファイルは1つもありません。";
        endmacro;
    }
    if( #cAttach == 1 ) {
        if( rightstr( $aAttach[0], 4 ) == ".zip" ) {
            message "添付ファイルは既に圧縮されてます。";
            endmacro;
        }
        $dest = $aAttach[0] + ".zip";
    } else {
        $dest = $aAttach[0] + "など.zip";
    }
    while(1) {
        #n = strstr( $dest, "\\" );
        if( #n < 0 ) {
            break;
        }
        $dest = midstr( $dest, #n + 1, 256 );
    }
    $dest = input( "圧縮して作成するファイル名は?", $dest );
    if( $dest == "" ) {
        endmacro;
    }
    if( #passwordlength != 0 ) {
        #i = 0;
        $password = "";
        #rand_init = tickcount + #i + val(second) + val(minute);
        while( #i < #passwordlength ) {
            if( #i == 0 ) {
                #rand = #rand_init / (10 + 26 + 26) % (10 + 26 + 26);
            } else if( #i == 1 ) {
                #rand = #rand_init % (10 + 26 + 26);
            } else {
                message "乱数を生成する用に、何かキーを押してください。(あ
と" + str( #passwordlength - #i ) + "回)";
                refreshdatetime;
                #rand = (tickcount + #i + val(second) + val(minute)) % (10 +
 26 + 26);
            }
            if( #rand < 10 ) {
                $rand = char( '0' + #rand );
            } else if( #rand < 10 + 26 ) {
                $rand = char( 'a' + #rand - 10 );
            } else {
                $rand = char( 'A' + #rand - 10 - 26 );
            }
            $password = $password + $rand;
            #i = #i + 1;
        }
    } else {
        if( $password == "*" ) {
            $password = input( "パスワードは?" );
            if( $password == "" ) {
                question "パスワード無しにしますか?";
                if( result != yes ) {
                    endmacro;
                }
            }
        }
    }

    //「ドキュメント」フォルダ配下に生成する?
    openreg "CURRENTUSER","Software\\Microsoft\\Windows\\CurrentVersion\\Exp
lorer\\Shell Folders";
    $outfolder = getregstr("Personal");
    closereg;
    $outfolder = $outfolder + "\\ZipTemp";
    runsync2 "cmd.exe /c rmdir /s /q \"" + $outfolder + "\"";       //古いフ
ァイルのゴミを削除
    #n = dllfunc("Bypass_CreateDirectory", $outfolder);

    $destbase = $dest;
    $dest = $outfolder + "\\" + $dest;
    #n = dllfunc("Bypass_SetFileAttributes", $dest, 0x00000020);
    #n = dllfunc("Bypass_DeleteFile", $dest);
    //添付ファイル圧縮-7zip.macで修正。
    //$cmd = "-j \"" + $dest + "\"";
    $cmd = "a \"" + $dest + "\"";
    #i = 0;
    while( #i < #cAttach ) {
        $cmd = $cmd + " \"" + $home + $account + "\\" + $aAttach[#i] + "\"";
        #i = #i + 1;
    }
    //添付ファイル圧縮-7zip.macで修正。
    //#n = dllfunc("Zip", hidemaruhandle(0), $cmd);

    if( $password != "" ) {
        $cmd = "-p" + $password + " " + $cmd;
    }
    $cmdline = "\"" + $7zip + "\" " + $cmd;
    runsync2 $cmdline;
    if( !result ) {
        message "7zipの実行に失敗しました。";
        endmacro;
    }
    if( ! existfile( $dest ) ) {
        message "7zipで生成されたはずのファイルがありません。たぶん圧縮に失
敗しています。\nファイル名 = " + $dest;
        endmacro;
    }
    #n = dllfunc("AddAttach", $dest);
    // ファイルの削除
    #n = dllfunc("Bypass_DeleteFile", $dest);
    #i = 0;
    while( #i < #cAttach ) {
        #n = dllfunc("UndoAttach", $aAttach[#i]);
        #i = #i + 1;
    }
    if( $password != "" ) {
        $to = dllfuncstr("CurrentHeader", "To");
        $toname = dllfuncstr("SetNameOnly", $to);
        if( $toname == "" ) {
            $toname = $to;
        }
        $body = gettext( 0, 0, 0, 3 );      //先頭の3行程度?

        $subject = dllfuncstr("CurrentHeader", "Subject");
        $sign = dllfuncstr("CurrentSignName");
        #attachhidemaru = hidemaruhandle(0);
        #n = dllfunc("NewMail");
        #n = dllfunc("SwitchSign", "");         //署名無しに一回切り替え
        #n = dllfunc("SetHeader", "To", $to );
        #n = dllfunc("SetHeader", "Subject", "パスワードの通知 - " + $subjec
t );
        gofiletop;
        beginsel;
        gofileend;
        delete;
        insert $body + "\n------------------------------------\n\n暗号化した
ファイルを別メールで送信しましたので、\nパスワードをお知らせします。\n\n" +
                "件名 : " + $subject + "\n" +
                "\n" +
                "添付ファイル名: " + $destbase + "\n" +
                "解凍パスワード: " + $password + "\n" +
                "\n" +
                "よろしくお願いします。\n";
        if( leftstr($sign, 1) == "\\" ) {
            //切り替えできない
            $signContent = dllfuncstr("LoadTemplate", "sign", $sign);
            if( $signContent != "" ) {
                insert "\n" + $signContent;
            }
        } else {
            #n = dllfunc("SwitchSign", $sign);          //署名をここで切り替え
        }
        gofiletop;
        setactivehidemaru #attachhidemaru;
    }
    endmacro;

[ ]
RE:00575 添付ファイル圧縮-パスワード別No.00576
k さん 19/11/01 17:47
 
ありがとうございます。
毎回手作業で修正していたので大変助かりました。

> 具体的な雰囲気がよく分からないのですが、元メールの本文の先頭3行程度をそ
>のまま入れて、その後ろに区切り線を入れるようにしてみたら、以下のようになり
>ました。
> ......
>    endmacro;

[ ]