Skip to content

fm_enable_voicemail wipes an existing mailbox's email and option flags - #43

Open
OlivierRunwolf wants to merge 1 commit into
mwtcmi:mainfrom
OlivierRunwolf:fix/enable-voicemail-wipes-settings
Open

fm_enable_voicemail wipes an existing mailbox's email and option flags#43
OlivierRunwolf wants to merge 1 commit into
mwtcmi:mainfrom
OlivierRunwolf:fix/enable-voicemail-wipes-settings

Conversation

@OlivierRunwolf

Copy link
Copy Markdown

The bug

addMailbox() rewrites the mailbox's entire voicemail.conf line (pwd,name,email,pager,options) and re-derives the novmpw / novmstar AstDB flags from whatever it's handed. The call site passed a fixed email => '' plus attach/envelope/vmdelete/saycid all 'no', and passed neither passlogin nor novmstar.

On a new mailbox that's correct. On a mailbox that already exists it destroys the voicemail-to-email address, resets all four option flags, and clears "require password to log in" and "disable * for voicemail".

# 9003=9933,Test,olivier@example.com,,attach=yes|saycid=no|envelope=yes|delete=no
fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","confirm":true}'
# 9003=1234,Test,,,attach=no|saycid=no|envelope=no|delete=no

The email is gone and the PIN is back to 1234. It's reachable by re-running enable to change nothing, or by enabling after a disable.

The fix

Read the box with getMailbox() first and feed every field back in.

Anything not modelled by name survives too: the existing option string is passed through as options, which addMailbox() parses before applying the individual keys, so imapuser / imappassword and anything else stored there are carried. The AstDB flags are read back and re-asserted — and if AstDB can't be read we omit them entirely and leave the previous behaviour rather than guessing.

email, attach, envelope, saycid and vmdelete are now accepted as params. I added them because without them there's no way to set the fields this PR starts preserving — fm_set_extension_email is the only existing route to any of them. If you'd rather keep this to a pure bug fix, say the word and I'll drop the params and resubmit — the preservation logic stands on its own.

password now defaults to the mailbox's current PIN instead of 1234, so enabling twice no longer resets it. New mailboxes are unaffected and still get the previous defaults.

The users.voicemail wiring from #36 is untouched.

Testing

FreePBX 17.0.30 / Asterisk 18, real box, on top of current main.

fwconsole frogman:tool fm_add_extension '{"ext":"9003","name":"UpstreamVmTest","vm":"yes","vmpwd":"9933","email":"olivier@tractiondk.com","confirm":true}'
  -> 9003=9933,UpstreamVmTest,olivier@tractiondk.com,,attach=no|saycid=no|envelope=no|delete=no

fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","attach":"yes","envelope":"yes","confirm":true}'
  -> 9003=9933,UpstreamVmTest,olivier@tractiondk.com,,attach=yes|saycid=no|envelope=yes|delete=no

fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","confirm":true}'          # this was the bug
  -> unchanged; email, PIN and both flags preserved

fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","context":"default","confirm":true}'
  -> unchanged; context param still honoured

fwconsole frogman:tool fm_disable_voicemail '{"ext":"9003","confirm":true}'
fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","password":"7788","confirm":true}'
  -> 9003=7788,UpstreamVmTest,,,attach=no|saycid=no|envelope=no|delete=no          # new box, clean defaults

fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003"}'                          # dry run
  -> "Would update the EXISTING voicemail box 9003 (context `default`, password `7788`).
      Email, pager and any option you did not name are preserved."

One coverage note: users.voicemail was already default at create on my test extension, so this run didn't re-demonstrate the #36 novm → context transition. That code path is unchanged by this PR.

Per CONTRIBUTING: I used Claude while writing this, and kept it out of the commit trailers.

addMailbox() rewrites the mailbox's entire voicemail.conf line
(pwd,name,email,pager,options) and re-derives the novmpw/novmstar AstDB
flags from whatever it is handed. The call site passed a fixed
email => '' plus attach/envelope/vmdelete/saycid all 'no', and passed
neither passlogin nor novmstar.

On a new mailbox that is correct. On a mailbox that already exists it
destroys the voicemail-to-email address, resets all four option flags, and
clears the "require password to log in" and "disable * for voicemail"
flags. Re-running enable to change nothing, or calling it after a disable,
silently loses the email.

Read the box with getMailbox() first and feed every field back in.
Anything not modelled by name survives too: the existing option string is
passed through as 'options', which addMailbox() parses before applying the
individual keys, so imapuser/imappassword and friends are carried. The
AstDB flags are read back and re-asserted; if AstDB can't be read we omit
them and leave the previous behaviour rather than guessing.

email, attach, envelope, saycid and vmdelete are now accepted as params,
since without them there is no way to set the fields this commit starts
preserving. password now defaults to the mailbox's current PIN instead of
1234, so enabling twice no longer resets it. New mailboxes are unaffected
and still get the previous defaults.

Tested on FreePBX 17.0.30 / Asterisk 18:

  fwconsole frogman:tool fm_add_extension '{"ext":"9003","name":"UpstreamVmTest","vm":"yes","vmpwd":"9933","email":"olivier@tractiondk.com","confirm":true}'
    -> 9003=9933,UpstreamVmTest,olivier@tractiondk.com,,attach=no|saycid=no|envelope=no|delete=no
  fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","attach":"yes","envelope":"yes","confirm":true}'
    -> 9003=9933,UpstreamVmTest,olivier@tractiondk.com,,attach=yes|saycid=no|envelope=yes|delete=no
  fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","confirm":true}'      # was the bug
    -> unchanged; email, PIN and both flags preserved
  fwconsole frogman:tool fm_disable_voicemail '{"ext":"9003","confirm":true}'
  fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003","password":"7788","confirm":true}'
    -> 9003=7788,UpstreamVmTest,,,attach=no|saycid=no|envelope=no|delete=no      # new box, clean defaults
  fwconsole frogman:tool fm_enable_voicemail '{"ext":"9003"}'                      # dry run
    -> "Would update the EXISTING voicemail box 9003 ... preserved."

The users.voicemail wiring is untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant