Debug fun: Folder names

Learned a lesson the hard way this week. debugging a problem where a code running against the

Database.views

property of a mail file with over 7000 folders couldn’t locate certain folders even though the interface clearly showed the folders as being there.

The ultimate cause was as simple as stupid: The code that ran against the Database.views property used the (undocumented) function

folder =  getParentFolder()

to ask the user to select a folder. This function shows the user a folder select dialog and returns the selected folders as an array.

The users would select folders but for some reason the subsequent code retrieving the selected folders from the database.views wouldn’t always find them.

After some debugging the cause turned out to be that the folder names that the

getParentFolder()

Returned does a

Fulltrim()

on the selected folder names before putting it into the array. Problem was however that on creation of the folder (which was not being done manually but through a script in which the user was prompted for a folder name) the user sometimes added leading, trailing or double spaces in the name.

On normal (manual) folder creation, folder names are automatically trimmed to remove obsolete or trailing spaces. When created through script though this isn’t automatically done. So the actual folder names (as listed in Database.views) contained the names with the spaces while the returned array of folder names from the getParentFolder() didn’t.
As trailing spaces are almost impossible to spot in the interface this went undetected.

folder name problem

So while normally (on ordinary folder creation) this Fulltrim() by the getParentFolder() wouldn’t have been a problem, the fact that the folders were being created through script – and users were entering names with extra spaces – meant it caused a discrepancy between the name returned by the function and the name actually used. Or, to put it differently: the inherent ‘human’ factor wasn’t being filtered out.

Lessons learned from this:

  1. Debugging a mail file with 7000 folders is a pain in the …
  2. Do a Fulltrim() on any folder name created through code
  3. And finally… NEVER underestimate the inherent capabilities of users to cause havoc (roughly 1 in 5 folder names contained trailing and or double spaces)

Leave a Reply