This Time Self-Hosted
dark mode light mode Search

Hack of the night

Okay it’s sunday night, and I’m at home. I don’t have anything to do a part the infamous paid job that’s driving me crazy and I’m waiting new info for. So what can I do? I can try to fix one of the KDE bugs I suffer from! 🙂
In particular, I gone for a KMail bug I encountered while replying to a mail of a friend of mine who’s using an Italian webmail (not the provider she’s connected with, or I’d have configured a Thunderbird on her box). Basically it does not accept some email/realname combinations if the realname contains @s .

Well the code where the problem was seemed to be KPIM::EmailParseResult KPIM::isValidEmailAddress(), that’s a quite complex stateful parser, which flow took me some time to understand. How could I fix the problem in such a messy (IMHO) code?

I opted for a rewrite, so I started, and rewrote the function replacing the stateful parser with a series of regular expressions and string checks. This makes it simpler in terms of LOC (61 insertions(+), 157 deletions(-)) and also, always IMHO, easier to read.
This time I didn’t work directly on KDE’s SVN as this change is not exactly small (while also kxkb fixes for KDE 3.5.1 were mostly a rewrite), and it might have some problems right now (I’m still compiling KMail to see if it works fine). It also does not consider a couple of error situations that it was considering before, that might be a showstopper (basically I don’t bail out if ‘,’ is present or if is at the end of the string. It shouldn’t be difficult to fix in case, tho.

Now does this mean I’m actually bored? Yeah it means that, but not only that, it also means that my personal life really needs a shock to change, shock that’s not going to happen in the next century or so…

Update: I’ve actually rebuilt KMail and my patch does work for most of the cases, actually it works for the present at the end of the string because of the way I structured it, returns a different error but it does not allow the wrong address to pass through. I checked with a forged To line with my email address and then tried also replying to my friend’s last mail. I attached the patch on the aforementioned bug and committed an ebuild using that patch in my overlay, but it’s using 3.5.1 version that’s still unreleased so people are not going to just emerge it to have the patch for now 😉
Should work with 3.5.0 too anyway.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.