• I Read The Comments (unregistered)

    private function isCorrectFileName($fileName) { $fileName = strtolower($fileName); $suffix = $this->getMessageNumberForAttachmentFilename() . $this->getAttachmentSuffix(); $suffixLocation = strpos($fileName, $suffix); if ($suffixLocation !== false) { $fileName = str_replace($suffix, '', $fileName); $fileName = str_replace($this->getAttachmentPrefix(), '', $fileName); if (is_numeric($fileName) && ($fileName == 0)) return true; } return FileNotFound; }

  • Robin (unregistered)

    It actually took me a while - including rereading the introduction - to realise WHY this would fail for message IDs greater than 999. And then having seen why it did - wow, whoever coded this obviously knew this wouldn't work for numbers past 1000. Or at least knew they were relying on there always being a 0 before the number in the filename, and didn't think to look up, or ask anyone, where this was coming from. So I'm not sure whether this is a case of

    1. developer simply putting in something which appears to work for reasons they don't understand, and accepting it
    2. developer knowing it would break later, but writing it anyway without even so much as an explanatory comment like // TODO: ensure this handles ids over 999

    Probably 1) is much more likely, but whichever it is, that's TRRRRRWTF.

  • ZZartin (unregistered)

    It's generic and will work on any system, assuming they use a very specific format for their file names.

  • coca cola original recipe (unregistered)

    Run inotify on the directory. Log stale files and notify.

  • markm (unregistered) in reply to Robin

    Instead of specifications you get a set of, say, 150, sample files "msg0000.wav" through "msg0149.wav". The message number begins with "0" in all the samples. So do you assume it always begins with zero, or that it's always four digits?

    That depends on whether or not you are an idiot.

  • bob wildcat (unregistered)

    The real WTF here is that you can enable email notifications directly in Asterisk

    https://github.com/asterisk/asterisk/blob/master/configs/samples/voicemail.conf.sample

  • Nuitari (unregistered)

    Why not just use the builtin asterisk feature of emailing the voicemail in the first place?

  • löchleindeluxe (unregistered)

    Chaotic neutral bugfix: replace the filename prefix with '0' instead.

    Chaotic evil bugfix: just remove the is_numeric, won't PHP autocast string to int if you have the arguments the right way around? And I doubt '' wouldn't cast to 0 there. I can totally see this being an error that was introduced during a code review/cleanup by somebody else who just saw "oh, it's casting to int and doesn't run is_numeric first, that's got to be wrong".

  • (nodebb)

    See, this is exactly why I like to code my stuff that interacts with other systems in the stupidest way possible. Your spec says the filename is going to be "msg<four digits>.wav"? Fine, that's what I'll code for. I'll test to see if it meets that criteria but I won't help you if it doesn't.

    You'd be amazed how quickly daft little edge cases get shaken out by this. Oh, it's four digits, except when it's five digits and the codec is raw G.711? Sure. Good to know.

    Oh and now we're using a totally different format string? I'll just write another decoder then.

    Keep it simple. Keep it about as technical as a hammer. Keep it working.

Leave a comment on “Voicemail to Email to Nothing at All”

Log In or post as a guest

Replying to comment #:

« Return to Article