This 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% [?]


Latest Comments