I use
system() call in order to call upon "/bin/mail" to send notification mail from a Unix daemon server program.
Everything works fine apart from character encoding problem in the subject. Basically the notification mails works by executing something like
Code:
snprintf(buffer,blen-1,
"echo '%s' | /usr/bin/mail -s '%s' '%s'",message, subject, to);
buffer[blen-1] = '\0';
int ret = system(buffer);
and this works just fine as long as there is no need to use MIME encoded-word syntax in the subject, i.e.
"=?charset?encoding?encoded text?="
and here lies the problem.
When using "mail" directly from the command line this also works fine but when called upon via the
system() call there is a different behavior.
If called from the command line with a subject that requires MIME encoded-word syntax the mail program will correctly do the encodation before sending it on to the MTA. However this does not seem to work when used through the
system() call. What happens is that when using the "mail" command through the
system() call no MIME word-encoding at all is done.
My initial assumption was that the
system() call would create a very "bare" environment where the locale (I use an utf-8 system) was not correct. However, running
system() and examining the environment it is the same environment as I have on the command line, i.e. I cannot spot any differences.
However, I still suspect this is the problem even though I couldn't spot any difference.
Is there anyone used to dealing with the complexity of character-encodation that could give me a hint on how to address this issue?