« IE6壊れる | Main | パートナー »

Maildirで特定のメールを転送

必要なメールだけ転送したいということがある。プロバイダ側で用意されていたりするが、自分のニーズにピッタリマッチしているわけでもなく。。。いっそのこと実装してしまえということに。
私のサーバはPostfix/Maildirを採用しているので1メール1ファイルになっていて処理しやすい。
条件にマッチするメールを探しだし
ヘッダーと本文の境を探す
ヘッダーからSubjectを抜き出す
ヘッダーからFromを抜き出す
awkでヘッダの読み飛ばしFrom行の表示
mailコマンドに食べさせる
touchコマンドで最終更新をアップデート
このコマンドをfetchmail-wrapper.shとかしてcronで回すとOK。
という手順。charsetにiso-2022-jpとかを含んでいないという点で手抜きだがPHS(Ad es)のメーラではちゃんと表示できた。携帯に転送するならsjisにiconvしたらいいのかも。


#!/bin/sh
MAILDIR="/home/odacle/Maildir/"
LASTUPDATE="/home/odalce/lastupdate.time"
MACTH="(foo@example.com|bar@example.com)"

# fechmail
/usr/pkg/bin/fetchmail -U >> $LOGFILE 2>&-

for mail in `find $MAILDIR/new/ $MAILDIR/cur/ -type f -newer $LASTUPDATE | xargs egrep -l $MATCH`
do
   HEAD=`egrep -n '^$' $mail | head -1 | sed 's/://'`
   SUBJECT=`sed -n 's/^Subject: \(.*\)/\1/p' $mail`
   FROM=`egrep -n '^From:' $mail | head -1 | sed 's/\(.*\):From.*/\1/'`
   HEAD=`expr $HEAD + 1`
   cat $mail | awk 'h<=NR || f==NR' h=$HEAD f=$FROM | mail -s "$SUBJECT" odacle@exaple.com
done

touch $LASTUPDATE


|
|

« IE6壊れる | Main | パートナー »

「UNIX」カテゴリの記事

Comments

Heya just wanted to give you a quick heads up and let you know a few of the pictures aren't loading properly. I'm not sure why but I think its a linking issue. I've tried it in two different web browsers and both show the same results.

Posted by: www.youtube.com | February 06, 2014 at 08:34 PM

A person necessarily assist to make significantly articles I might state. That is the first time I frequented your web page and to this point? I amazed with the research you made to make this particular put up incredible. Great activity!

Posted by: kasinot | March 25, 2014 at 12:47 AM

If you are going for best contents like myself, only go to see this web page daily for the reason that it provides quality contents, thanks

Posted by: jackpot 6000 | April 03, 2014 at 04:26 PM

Hey very nice website!! Man .. Beautiful .. Wonderful .. I will bookmark your blog and take the feeds additionally? I am happy to seek out a lot of useful info here within the put up, we need work out extra techniques on this regard, thanks for sharing. . . . . .

Posted by: spilleautomater | April 12, 2014 at 01:14 AM

Hey! Someone in my Myspace group shared this site with us so I came to look it over. I'm definitely loving the information. I'm book-marking and will be tweeting this to my followers! Great blog and excellent style and design.

Posted by: spilleautomater bonus | April 16, 2014 at 04:55 PM

I was wondering if you ever thought of changing the layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?

Posted by: beste spilleautomater pa nett | April 17, 2014 at 07:58 PM

Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! However, how could we communicate?

Posted by: spilleautomater | April 18, 2014 at 12:02 AM

There is definately a lot to learn about this topic. I love all of the points you made.

Posted by: spilleautomater | August 13, 2014 at 12:30 PM

This is my first time visit at here and i am in fact impressed to read everthing at one place.

Posted by: ab crunch machine | September 12, 2014 at 03:13 PM

Highly descriptive post, I liked that a lot. Will there be a part 2?

Posted by: youtube.Com | October 13, 2014 at 06:25 AM

Appreciating the commitment you put into your website and in depth information you provide. It's great to come across a blog every once in a while that isn't the same out of date rehashed information. Great read! I've saved your site and I'm including your RSS feeds to my Google account.

Posted by: best dating sites | January 12, 2015 at 07:40 PM

Amazing! Its really amazing piece of writing, I have got much clear idea about from this article.

Posted by: best dating sites | January 18, 2015 at 04:15 PM

Remarkable things here. I am very glad to peer your article. Thanks so much and I am having a look ahead to contact you. Will you kindly drop me a mail? blogesaurus.com quest bars

Posted by: best place to buy quest bars uk | January 23, 2015 at 07:32 PM

For newest news you have to go to see world-wide-web and on internet I found this website as a finest web site for latest updates. blogesaurus.com quest bars

Posted by: quest protein bars nz | January 24, 2015 at 04:10 PM

Your mode of describing all in this article is genuinely fastidious, every one can effortlessly be aware of it, Thanks a lot. blogesaurus.com quest bars

Posted by: quest bars lowest price | January 24, 2015 at 11:07 PM

What a information of un-ambiguity and preserveness of valuable know-how about unpredicted feelings.

Posted by: free music downloads | February 06, 2015 at 09:45 PM

Hello there! Do you know if they make any plugins to protect against hackers? I'm kinda paranoid about losing everything I've worked hard on. Any suggestions?

Posted by: smarturl.it | February 08, 2015 at 11:00 AM

It's fantastic that you are getting thoughts from this paragraph as well as from our discussion made here.

Posted by: http://www.codecademy.com | February 15, 2015 at 07:00 AM

What's up, after reading this amazing article i am also happy to share my familiarity here with mates.

Posted by: Otkup Srebra | February 24, 2015 at 09:15 AM

I like the valuable information you supply in your articles. I will bookmark your weblog and test again here regularly. I'm moderately certain I will learn lots of new stuff right here! Best of luck for the next!

Posted by: Vicki | March 14, 2015 at 01:16 PM

There's definately a lot to know about this subject. I like all of the points you hae made.

Posted by: servis za pranje tepiha nis | March 15, 2015 at 02:04 PM

Hey there, You've done an excellent job. I'll definitely digg itt and personally recommend to my friends. I am sure they'll be benefited from this web site.

Posted by: That Thing Called Tadhana Full Movie Online | March 18, 2015 at 03:23 AM

Nice post. I used to be checking continuously this weblog and I'm impressed! Extremely useful nfo particularly the final phase : ) I handle such info much. I used too be looking for this particular info for a loing time. Thanks annd god luck.

Posted by: Crazy Beautiful You Full Movie | March 24, 2015 at 10:23 PM

Heya i'm for the first time here. I came across this board and I to find It truly helpful & it helped me out a lot. I hope to give one thing again and help others such as you helped me.

Posted by: quality web graphics | March 29, 2015 at 06:53 AM

Remarkable things here. I'm very satisfied to see your post. Thank you so much and I am having a look ahead to touch you. Will you please drop me a mail?

Posted by: Walter Synalovski | April 03, 2015 at 08:45 AM

I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to doo it for you? Plz reply as I'm looking to construct my own blog and would like to find out where u got this from. cheers

Posted by: knjigovodstvene agencije beograd | April 05, 2015 at 11:49 AM

Do you have a spam issue on this blog; I also am a blogger, and I waas curious about your situation; wee havve created some nice procedures and we aare looking to swap techniques wityh others, bee sure to shokot me an e-mail if interested.

Posted by: gynecology.co.il | April 08, 2015 at 12:27 AM

Your mode of describing all in this piece of writing iis truly fastidious, all be capable of simply know it, Thanks a lot.

Posted by: wc papir | April 10, 2015 at 12:03 PM

An intriguing discussion is definitely worth comment. I think that you need to publish more about this subject matter, it may not be a taboo matter but typically people do not discuss such topics. To the next! Cheers!!

Posted by: θερμοπροσοψη θεσσαλονικη | April 10, 2015 at 08:43 PM

If you want to take a good deal from this paragraph then you have to apply such strategies to your won weblog.

Posted by: θερμοπροσοψη | April 19, 2015 at 03:36 PM

First off I would like to say awesome blog! I had a quick question in which I'd like to ask if you don't mind. I was interested to know how you center yourself and clear your thoughts prior to writing. I have had difficulty clearing my thoughts in getting my ideas out. I truly do enjoy writing but it just seems like the first 10 to 15 minutes tend to be lost simply just trying to figure out how to begin. Any ideas or hints? Cheers!

Posted by: buy youtube views from youtube advertising | April 23, 2015 at 06:05 PM

I always used to read piece of writing in news papers but now as I am a user of web thus from now I am using net for articles or reviews, thanks to web.

Posted by: phenylpiracetam dosage | April 30, 2015 at 01:05 PM

Asking questions are genuinely pleasant thing if you are not understanding anything entirely, except this article provides nice understanding even.

Posted by: David Rohl | May 28, 2015 at 02:17 PM

It's hard to come by educate people for this subject, however, yyou seem like you know what you're talking about! Thanks

Posted by: pranje tepiha sarajevo | May 30, 2015 at 06:28 PM

Do you have any video of that? I'd care to find out more details.

Posted by: online guitar lessons for beginners | July 01, 2015 at 10:40 PM

Exceptional post but I was wondering if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit further. Thank you!

Posted by: taruhan judi online | July 05, 2015 at 09:05 AM

I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I'm looking to design my own blog and would like to know where u got this from. thank you

Posted by: desmond ong pandora | July 09, 2015 at 10:07 AM

It is appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you some interesting things or tips. Perhaps you could write next articles referring to this article. I want to read even more things about it!

Posted by: Unlimited Abundance discount | August 15, 2015 at 03:29 PM

Link exchange is nothing else except it is just placing the other person's website link on your page at appropriate place and other person will also do same in support of you.

Posted by: Tomoko | October 07, 2015 at 08:58 AM

Hi, I do believe this is an excellent web site. I stumbleduplon it ;) I will revisit yett again since I saved as a favorite it. Money and freedom is thhe greatest way to change, may you be rich and continnue to help others.

Posted by: Melba | October 07, 2015 at 09:52 PM

I'm amazed, I must say. Seldom do I encounter a blog that's equally educative and interesting, and without a doubt, you've hit the nail on the head. Thhe issue is something which too feww men and women are speaking intelligently about. I'm very happy that I found this during my hunt for something regarding this.

Posted by: kacer om kicau mp3 | October 09, 2015 at 01:56 AM

Thanks for a marvelous posting! I seriously enjoyed rerading it, you could bee a great author. I will make certain too bookmark your blog and will come back sometime soon. I want tto encourage that you continue your great job, have a nice weekend!

Posted by: murai batu pelor mas | October 09, 2015 at 05:33 AM

I couldn't resist commenting. Exceptionally well written!

Posted by: pentet gacor terus | October 09, 2015 at 07:17 AM

Fine way of telling, and pleasant piece of writing to take facts onn the topic of my presentation subject matter, which i am goinng to convey in university.

Posted by: Mammie | October 09, 2015 at 09:00 AM

That is really interesting, You are an excessively skilled blogger. I have joined your feed and sit up for looking for extra of your great post. Additionally, I've shared your web site in my social networks

Posted by: Steffen | October 13, 2015 at 07:48 PM

Hey there, I think your website might be having browser compatibility issues. When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, amazing blog!

Posted by: Terri | October 21, 2015 at 12:13 PM

Post a comment



(Not displayed with comment.)




TrackBack

TrackBack URL for this entry:
http://app.cocolog-nifty.com/t/trackback/45549/40486186

Listed below are links to weblogs that reference Maildirで特定のメールを転送:

« IE6壊れる | Main | パートナー »