00229.jpg
Sarah showing her true colours
00220.jpg
Luke in the Christmas spirit
Last shot, bye bye volcano
Clownfish
IMG_0284.jpg
HPIM0920.JPG

 

April 2009
M T W T F S S
« Feb   May »
 12345
6789101112
13141516171819
20212223242526
2728293031  

searching for mail in Cyrus

TUX logoThis is a simple post on how to do some nifty little script-fu to search for emails and move them to a different folder in order for Cyrus to be able to show them.

The first thing to do is to search for the search term that you want. For this, I rely on grep and pipe the output to a file:

[root@mailserver user]# grep -r -i 'searchstring' bcc > searchstring.txt
...
# this can take hours depending on the size of the folder to search

This searches for the string 'searchstring' in the bcc folder and dumps the output into a file called searchstring.txt

After that's done, you'll end up with a file that contains a match on each line:

[root@mailserver user]# vi searchstring.txt
...
bcc/239823.:searchstring<o:p></o:p></span></font></pre><pre style=3D"margin-top: 0cm; =^M
....
Binary file bcc/cyrus.cache matches
...
[root@mailserver user]#

As you can see, it also matches the cyrus.cache file which we don't need because we'll need to get that rebuilt anyway. We then need to create a folder in an existing mail account (or use and existing one) and drop the files into that folder using a combination of shell commands (I've chosen grep, sed and xargs):

[root@mailserver user]# cat searchstring.txt | grep '^bcc' | sed 's/\:.*//' | xargs -Ifilename cp -vrp filename ../../t/user/account/searchstring_folder/
....
...
..
[root@mailserver user]#

That little piece of code reads the file, discards any line that doesn't begin with 'bcc' (grep), substitutes the end of the string with nothing (sed) and then copies the file to the new location (xargs). You then simply need to get cyrus to rebuild the mailbox to see the messages in their entirity.

Be careful, you could potentially end up destroying your Cyrus mailboxes through stupidity (either yours or Cyrus') and I won't be held responsible.

Popularity: 17% [?]

Everybody's a critic WTF?? Nothing about this made senseas useful as a blindfolded monkey throwing dartsmediocre ... at bestsolved my problem but needed modificationspectacular.  \'Nuff said (Be the first to rate this post)
Loading ... Loading ...

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>