Linux Cat mutt emails from maildir - mutt

I have managed to link a gmail account up with offlineimap and mutt. I have a script that runs and I want to read and check my new emails. Is there a way for me to do something like cat /path/to/mutt/emails | grep "text search"?

Provided you are using the Maildir format to store the mail locally, your email will be stored one email per file. You cannot do a simple cat in this case. You would need to find the email files first, using for example find. The Maildir format also defines to folders cur and new, so you could do something like this:
find <path-to-your-maildir>/new -type f | xargs grep "text search"
That might be helpful, when doing some low level scripts or when debugging the mail setup. However, I am also wondering why you would do it this way. Mutt has a very powerful search and tag syntax (much better than anything provided by a GUI mail client) - http://www.mutt.org/doc/devel/manual.html#patterns. Searches in email bodies can slow things down of course, depending of the size of your mailbox. For these cases there are external tools which can be integrated into mutt and fulltext index your emails, so that searches within the email bodies are much faster. Personally I am using mu, but there are alternatives - http://dev.mutt.org/trac/wiki/UseCases/SearchingMail

Related

Mutt, how to stop mutt from changing email names

I recently switched to Mutt. Being able to backing up emails sounds cool. I use rsync to do so but I have a big headache. I use Maildir format. Each time Mutt opens an email, it changes the file name of the email, e.g. it likes to add one ",S" to the end. Then weeks later when I back up my mails, rsync is driven crazy. I guess Mutt does so because of some concurrency issues but as a personal user I do not have to worry about this. I hope to tell Mutt to keep the names of email files permanently unchanged. Question: how?
the ,S ismaildir flag for seen ("mark as read"). that's the way maildirs work, i can't tell whether you can run mutt in read-only mode as far as that is concerned.
usually, when working with maildirs, it's a better idea to use a maildir-awaresynchronization like mbsync. it will know of those flags and synchronize more efficiently because it can rely on all involved utilities to be aware of the ways to handle maildirs (that is, don't change files in-place, how to set flags etc).

Aspell add word to personal dictionary using pipes

I'm using Aspell through pipes, and would like to know how can I add a new word to my personal dictionary.
For example, to check spelling for the word "tesst" I use:
echo tesst|aspell -a -p .aspell.en_US.pws
Here is explained that I can use "*word" to add this word to my personal dictionary:
echo *tesst|aspell -a -p .aspell.en_US.pws
But it doesn't.
What I'm doing wrong?.
Have you saved your personal dictionary ?
A line prefixed with # will cause the personal dictionaries to be saved.
Hope this helps
I could not make Aspell6 working with personal dictionaries. Instead I had to create extra-dictionaries as I explain at http://vouters.dyndns.org/tima/Linux-Windows-Perl-Aspell-Determining_the_country_of_a_Web_query.html. Otherwise I was getting an error from Aspell. If you read the Perl code at the above URL it uses the Aspell6 'extra-dicts' feature. This was my only workaround to Aspell's personal dictionaries.
FYI: the goal of the Perl code is to determine the language spoken by a Web visitor leaving his query into a company's Web search engine. All the queries are stored within an xlsx Excel file. The final purpose is to determine whether the translation of a company's English written Web document is financially worth to translate it to a local dialect.
In the hope this will help you.
Philippe Vouters (Fontainebleau/France)

C++ Windows - fill password field of system("run as")

I know there are many other ways to do this but I want to know how to fill in the password question of the windows the run as command automatically.
system("runas /user:\"benedikt\" \"xy.exe\"");
is there any way to do this? I googled a long time but i only found a lot of tools doing wat I want to do and not a way to do this for myself.
PS: I do not want to use any .Net functions.
OK, I'm going out on a limb here, because I'm not 100% sure that there isn't some (convoluted) way to achieve what you are looking for using stock runas. However, Why doesn't the RunAs program accept a password on the command line?, suggests there isn't - deliberately so to prevent "security issues" with plain-text passwords in command lines, batch files and tools that can view a command line (like Process Explorer).
BTW, a simple echo <password> | runas /user:<user> <command> doesn't seem to work either (it skips over the prompt for the password, but the password itself is not read by runas it seems).
So I guess you have to resort to some other means, like using the real API behind it all: CreateProcessWithLogin.

a program to monitor a directory on Linux

There is a directory where a buddy adds new builds of a product.
The listing looks like this
$ ls path-to-dir/
01
02
03
04
$
where the numbers listed are not files but names of directories containing the builds.
I have to manually go and check every time whether there is a new build or not. I am looking for a way to automate this, so that the program can send an email to some people (including me) whenever path-to-dir/ is updated.
Do we have an already existing utility or a Perl library that does this?
inotify.h does something similar, but it is not supported on my kernel (2.6.9).
I think there can be an easy way in Perl.
Do you think this will work?
Keep running a loop in Perl that does a ls path-to-dir/ after, say, every 5 minutes and stores the results in an array. If it finds that the new results are different from the old results, it sends out an email using Mail or Email.
If you're going for perl, I'm sure the excellent File::ChangeNotify module will be extremely helpful to you. It can use inotify, if available, but also all sorts of other file-watching mechanisms provided by different platforms. Also, as a fallback, it has its own watching implementation, which works on every platform, but is less efficient than the specialized ones.
Checking for different ls output would send a message even when something is deleted or renamed in the directory. You could instead look for files with an mtime newer than the last message sent.
Here's an example in bash, you can run it every 5 minutes:
now=`date +%Y%m%d%H%M.%S`
if [ ! -f "/path/to/cache/file" ] || [ -n "`find /path/to/build/dir -type f -newer /path/to/cache/file`" ]
then
touch /path/to/cache/file -t "$now"
sendmail -t <<< "
To: aaa#bbb.ccc
To: xxx#yyy.zzz
Subject: New files found
Dear friend,
I have found a couple of new files.
"
fi
Can't it be a simple shell script?
while :;do
n = 'ls -al path-to-dir | wc -l'
if n -gt old_n
# your Mail code here; set old_n=n also
fi
sleep 5
done
Yes, a loop in Perl as described would do the trick.
You could keep a track of when the directory was last modified; if it hasn't changed, there isn't a new build. If it has changed, an old build might have been deleted or a new one added. You probably don't want to send alerts when old builds are removed; it is crucial that the email is sent when new builds are added.
However, I think that msw has the right idea; the build should notify when it has completed the copy out to the new directory. It should be a script that can be changed to notify the correct list of people - rather than a hard-wired list of names in the makefile or whatever other build control system you use.
you could use dnotify it is the predecessor of inotify and should be available on your kernel. It is still supported by newer kernels.

RTF / doc / docx text extraction in program written in C++/Qt

I am writing some program in Qt/C++, and I need to read text from Microsoft Word/RTF/docx files.
And I am looking for some command-line program that can make that extraction. It may be several programs.
The closest thing I found is DocToText, but it has several bugs, so I can't use it.
I have also Microsoft Word installed on the PC. Maybe there is some way to read text using it (have no idea how to use COM)?
Now, this is pretty ugly and pretty hacky, but it seems to work for me for basic text extraction. Obviously to use this in a Qt program you'd have to spawn a process for it etc, but the command line I've hacked together is:
unzip -p file.docx | grep '<w:t' | sed 's/<[^<]*>//g' | grep -v '^[[:space:]]*$'
So that's:
unzip -p file.docx: -p == "unzip to stdout"
grep '<w:t': Grab just the lines containing '<w:t' (<w:t> is the Word 2007 XML element for "text", as far as I can tell)
sed 's/<[^<]>//g'*: Remove everything inside tags
grep -v '^[[:space:]]$'*: Remove blank lines
There is likely a more efficient way to do this, but it seems to work for me on the few docs I've tested it with.
As far as I'm aware, unzip, grep and sed all have ports for Windows and any of the Unixes, so it should be reasonably cross-platform. Despit being a bit of an ugly hack ;)
Try Apache Tika
I recommend not to use COM as this would defeat the usage of a portable library like Qt in the first place.
You might want to use the classic catdoc or a similar tool such as wvWare.
Note that although the catdoc author claims that catdoc doesn't work under Windows, there is a posting of 2001 which states the opposite.
To read .doc files you can use the structured storage API. A .doc is basically a structured storage repository with various streams corresponding to the various parts of the document.
Be warned that it is quite a hairy API and that even using this API, a .doc file can be quite messy to look at.
Ofcouse this is still windows only but atleast it's not COM. just a plain old C API.
This might help. It is cross-platform and has an API http://www.winfield.demon.nl/
Otherwise the iFilter methods are the way to go if this is windows only. It will allow you to parse anything that has an iFilter on your system. Here is examples of this http://the-lazy-programmer.com/blog/?p=8 . I have used iFilter from the C# end of things quite a bit.