Fix bug#9418 (improved).

This PR fixes Fix bug#9418.
There are test cases which I expect to be fixed in below.

http://bugs.otrs.org/show_bug.cgi?id=9418