Quantcast
Channel: Planet DTP@jp
Viewing all articles
Browse latest Browse all 4816

FORCE: [eMail] 送信前にメール本文をチェックする

$
0
0

いつからですかねぇ
UTF8メールがおおでを振って行き交うようになったのは…
CJKとか…国別言語別対応面倒だからUTFにしちゃえばいいでしょ
なのかなぁ
まぁ、後数年?経てば、色々なケースが適応されて
文字化け?問題も解決するんでしょうか。
(例えば:本文は全てJIS内だけど、添付ファイルのファイル名がUTFで本文インライン上に配置されているとか)
さて
メール送信前にメール本文中の文字をチェックするスクリプトです
業務で作成したのを少し手直ししたので公開

手順
1:解凍したスクリプトはスクリプトメニューに

2:メール本文を書いたら

Website_image00261101_132842

3:メール本文全てを選択して

Website_image00261101_132850

4:メール本文をコピーします

Website_image00261101_132902


5:出来たらスクリプトメニューから実行

Website_image00261101_132910


6:JIS外の文字があると〓に置き換えます

Website_image00261101_132936


(*
クリップボード内のテキストに
JIS外の文字があるか?を確認して
テキストエディットに貼付けます
JIS外の文字は〓に置き換えます。
テキストエディターにペースト後
〓を赤く塗ります
クリップボード内のテキストを取得する際に
処理によって違う場合?に置き換わるので
?マークは緑に塗り注意喚起します
http://force4u.cocolog-nifty.com/
*)

(*
ここは設定項目です
メールアプリによる改行の扱いの違いを設定
AppleMail app = 0
Thunderbird = 1
Microsoft Entourage 13 = 2
*)
propertytheEmailApp : 0


------------------------------------
onrun
------------デフォルトのディレクトリ
tellapplication"Finder"
-----このスクリプトへのパスを格納
settheDefaultLocationto ((containerof (path tome)) astext) astext
endtell
------辞書ファイル(といってもテキストですが)
settheJisDicto"ISO-2022-JP-Dic.txt"
-----ファイルまでのパスをエイリアスにして格納
settheJisDicPathto (theDefaultLocation& theJisDic) asalias
------------ファイルを「open」に渡す
opentheJisDicPath
endrun


onopenobjDrop
-----辞書ファイルのエイリアスを取得
settheFileAliastoobjDropasalias
------選択したファイルのUNIXパスを取得
settheUnixPasstoPOSIX pathoftheFileAliasastext
----辞書ファイルを読み込みUTF8で格納する
settheDatato (do shell script"cat " & theUnixPass) as«class utf8»
----格納したデータをテキストにする
settheDatatotheDataastext
-----クリップボードから取得した時の値の初期化
settheMailTextto""
----メールアプリ毎の文字と改行の処理
try
----AppleMail
iftheEmailAppis 0 then
-----クリップボードの中身をテキストで格納
settheMailTexttoget (the clipboardas«class utf8»)
-----テキストに変更
settheMailTexttotheMailTextastext
-----区切り文字を改行コードに変更
setAppleScript's text item delimitersto {"\n"}

-----Thunderbird
elseiftheEmailAppis 1 then
-----クリップボードの中身をテキストで格納
settheMailTexttoget (the clipboardas«class utf8»)
-----テキストに変更
settheMailTexttotheMailTextastext
-----区切り文字を改行コードに変更
setAppleScript's text item delimitersto {"\n"}

-----Microsoft Entourage(まぁ不要ですけど
elseiftheEmailAppis 2 then
-----クリップボードの中身をテキストで格納
settheMailTexttoget (the clipboardasUnicode text)
-----テキストに変更
settheMailTexttotheMailTextastext
-----区切り文字を改行コードに変更
setAppleScript's text item delimitersto {"\r"}
endif
endtry
-----改行毎にリストにして格納
settheFileTypeListtoeverytext itemoftheMailTextaslist
-----区切り文字を戻す
setAppleScript's text item delimitersto {""}
-----何行あるか?(データ件数=繰り返し数)を数える
setnumListLinetocountoftheFileTypeList
-----行数カウンタ初期化
setnumLineto 0 asnumber
-----文字の置き換えが発生したか?カウンタ
setnumNoJisChrto 0
-----繰り返しカウンターも初期化
setnumListLineCntto 0 asnumber
-----行毎の繰り返し
repeatnumListLinetimes
-----行カウンターアップ
setnumListLineCnttonumListLineCnt + 1 asnumber
-----行数カウンタ行を1行だけ取得して格納
settheLineDateto (itemnumListLineCntoftheFileTypeList) astext
-----文字数数える
setnumPcntto (countoftheLineDate) asnumber
----文字毎のだぶるクオテーションを区切り文字に
setAppleScript's text item delimitersto {""}
------文字毎にリストに格納する
settheLineDate1toeverytext itemoftheLineDateaslist
-------文字毎の繰り返しカウンターを初期化
setnumCntRepeatto 0 asnumber
-----文字毎の繰り返し
repeatnumPcnttimes
-----文字カウンターアップ
setnumCntRepeattonumCntRepeat + 1
-----1文字づつ
settheChkMailTextto (itemnumCntRepeatoftheLineDate) astext
------辞書ファイルの中に文字があるか?調べる
iftheDatacontainstheChkMailTextthen
---あればそのまま
else
-----辞書ファイルに無い文字があったら
-----置き換え文字を〓に指定
settheTextto"" astext
-----辞書外の文字カウンタUP
setnumNoJisChrtonumNoJisChr + 1
logtheChkMailText
------辞書ファイルの中に無い文字だったら〓に置き換える
settheMailTexttodoReplace(theMailText, theChkMailText, theText)
endif
-----文字毎リピートの終わり
endrepeat
-----行毎リピートの終わり
endrepeat

------結果発表
ifnumNoJisChris 0 then
-----置き換えが発生しなかったらOKダイアログ
tellapplication"Finder"
display alert"メールチェックOK" asinformationalgiving up after 1
endtell
else
-----文字の置き換えが発生したらテキストエディタに表示する
-----色指定
setredColorto {65535, 0, 0}
setgreenColorto {0, 41354, 0}
-----?マークを緑に塗るための文字指定
settheQTextto"?" astext
----置き換え終わった文字をクリップボードに戻す
set the clipboard totheMailTextastext
------結果をテキストエディタに表示する
tellapplication"TextEdit" tolaunch
tellapplication"TextEdit"
----新しいドキュメントを作成する
makenewdocumentwith properties {text:theMailText}
telltextofdocument 1
---置き換え文字を赤く塗る
setthecolorofeverycharacterwhereitistheTexttoredColor
setthecolorofeverycharacterwhereitistheQTexttogreenColor

endtell
endtell
tellapplication"TextEdit" toactivate
endif
endopen






----------------#ここから文字の置き換えサブルーチン
todoReplace(theText, orgStr, newStr)
setoldDelimtoAppleScript's text item delimiters
setAppleScript's text item delimiterstoorgStr
settmpListtoeverytext itemoftheText
setAppleScript's text item delimiterstonewStr
settmpStrtotmpListastext
setAppleScript's text item delimiterstooldDelim
returntmpStr
enddoReplace


「JIS-Chker-v2.zip」をダウンロード


「JIS-Chker-v2.rtf」をダウンロード

アントラージュ等で
このダイアログが出ても、「どの文字?」が解らない時用です

Website_image00261101_110421



Viewing all articles
Browse latest Browse all 4816

Trending Articles