Bugmonkey script to alert user of incorrect mailbox - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com 2013-05-19T23:16:53Z http://fogbugz.stackexchange.com/feeds/question/10098 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://fogbugz.stackexchange.com/questions/10098/bugmonkey-script-to-alert-user-of-incorrect-mailbox Bugmonkey script to alert user of incorrect mailbox Ben McCormack 2012-03-12T16:47:41Z 2012-10-11T17:38:28Z <p>This is a script that lets you define a dictionary of user and email mappings. When the user sends or replies to an email, if the email selected for the user does not match what is in the dictionary, the user will be alerted to change the selected mailbox:</p> <p><img src="http://i.imgur.com/LIQ84.png" alt="alt text"></p> <pre><code>name: Alert If Email is Wrong description: Define a dictionary of users and email addresses and alert the user if they are using the wrong email address. author: Ben McCormack version: 1.0.0.0 js: var sUsers = {}; //define your user and mailbox associations here. The user name must match //the full name of the user in FogBugz. The mailbox must match an available //option in the From field when sending an email. sUsers['Ben McCormack'] = '"Ben McCormack" &lt;cases@benmtest.fogbugz.com&gt;'; sUsers['Barney Rubble'] = '"FogBugz On Demand" &lt;cases@benmtest.fogbugz.com&gt;'; var sDefaultBackgroundCSS = $('div.body.editable div.emailHeader').css('background-color'); //main is called at the bottom function main() { if (!replyingToEmail()){ return; } if (!emailAddressMatchesUser()){ notifyUserOfMismatch(); } } //this function tells us if we're currently replying to an email function replyingToEmail(){ return $('div.body.editable .emailHeader').length !== 0; } //this function tells us if the "From" address matches the current //user. You can define this however you want. function emailAddressMatchesUser(){ var sSelectedEmailAddress = $('select#sFrom option[selected="selected"]').text(); var sCurrentUser = GetFullName(); if (sUsers[sCurrentUser]===undefined){ //this user didn't have a mailbox defined, so just return true return true; } return sUsers[sCurrentUser] === sSelectedEmailAddress; } //this function defines what happens when the From address doesn't //match what is expected for this user. You can define this however //you want. function notifyUserOfMismatch(){ if ($('div.emailMismatch').length !== 0) { return; } sUser = GetFullName(); $('div.body.editable div.emailHeader').css('background-color','#CC5151'); sMessage = 'ALERT! You should change the From address to: &lt;br&gt;' + htmlEncode(sUsers[sUser]); $('div.body.editable div.emailHeader').prepend('&lt;div class="emailMismatch"&gt;' + sMessage + '&lt;/div&gt;'); } function clearNotification(){ if ($('div.emailMismatch').length !== 0) { $('div.emailMismatch').remove(); $('div.body.editable div.emailHeader').css('background-color',sDefaultBackgroundCSS) } } function htmlEncode(value){ return $('&lt;div/&gt;').text(value).html(); } $(document).ready(function(){ main(); }); $(window).on('BugViewChange', function(event) { main(); }); css: div.emailMismatch{ font-weight: bold; font-size: 120%; } </code></pre> <p>There are several other variations of this in the answers below.</p> http://fogbugz.stackexchange.com/questions/10098/bugmonkey-script-to-alert-user-of-incorrect-mailbox/10281#10281 Answer by Noah Baker for Bugmonkey script to alert user of incorrect mailbox Noah Baker 2012-04-16T23:41:45Z 2012-04-17T03:50:50Z <p>Our Fogbugz installation had some email addresses that were important for receiving email/cases, but we didn't necessarily want to let people know that they were named, much less let them send email from them.</p> <p>There were addresses that we considered "inbound only", so showing them as an option in the "From" drop down just cluttered things. Also, there was one email address that we didn't want people to be able to send from the "generic" version - instead, we wanted them to use their "personal" version of the shared address. Removing the shared version of this address (websupport) was needed. Therefore, we needed a way to remove email address options from the dropdown alltogether, which is how we arrived at the following customization:</p> <pre><code>name: RemoveOptions_sFrom description: Removes specified email addresses from from options when sending/replying/forwarding email in Fogbugz author: Michael Kandy version: 2.3.2 js: $(function(){ if (!$('#bugviewContainer').length) return; var chgMail = function(sCommand) { $('select#sFrom &gt; option:contains("uiccgitckrptng@somecompany.com")').remove(); $('select#sFrom &gt; option:contains("agencydownloads@somecompany.com")').remove(); $('select#sFrom &gt; option:contains("\"Websupport\" &lt;websupport@somecompany.com&gt;")').remove(); $('select#sFrom &gt; option:contains("systems_entry@somecompany.com")').remove(); $('select#sFrom &gt; option:contains("systems_fogbugz@somecompany.com")').remove(); DropListControl.refresh($("#sFrom")[0]); }; chgMail('load'); chgMail('reply'); chgMail('forward'); $(window).on('BugViewChange', function(e, data) { chgMail(data.sCommand); }); }); </code></pre> http://fogbugz.stackexchange.com/questions/10098/bugmonkey-script-to-alert-user-of-incorrect-mailbox/10859#10859 Answer by adambox for Bugmonkey script to alert user of incorrect mailbox adambox 2012-10-11T17:38:00Z 2012-10-11T17:38:00Z <p>I modified Ben's script for my own use. I wanted to be alerted whenever the email address of the selected option wasn't in a short list of ones I use.</p> <pre><code>name: Alert If Email is Wrong description: Define a dictionary of users and email addresses and alert the user if they are using the wrong email address. author: Ben McCormack and Adam Wishneusky version: 1.1.0.0 js: $(document).ready(function(){ if (!$('#bugviewContainer').length) return; var sAddresses= []; sAddresses[0] = 'customer-service@fogcreek.com'; sAddresses[1] = 'support@copilot.com'; var sDefaultBackgroundCSS = "rgb(224, 233, 241)"; function main(sNew) { console.log('main called with sNew = ' + sNew); if ($('div.body.editable .emailHeader').length == 0) return; if (!emailAddressMatchesUser(sNew)) notifyUserOfMismatch(); else clearNotification(); } function emailAddressMatchesUser(sNew){ console.log('emailAddressMatchesUser called with sNew = ' + sNew); var sSelectedEmailAddress = ''; if (sNew == null) { console.log('sNew is null'); sSelectedEmailAddress = $('select#sFrom option[selected="selected"]').text(); } else sSelectedEmailAddress = sNew; for (var i = 0; i &lt; sAddresses.length; i++) { console.log('testing ' + sAddresses[i]); if (sSelectedEmailAddress.search(sAddresses[i]) &gt; -1){ console.log('match!'); return true; } } console.log('no match'); return false; } function notifyUserOfMismatch(){ console.log('mismatch!'); if ($('div.emailMismatch').length !== 0) { return; } $('div.body.editable div.emailHeader').css('background-color','#CC5151'); sMessage = 'ALERT! not one of your mailboxes.'; $('div.body.editable div.emailHeader').prepend('&lt;div class="emailMismatch"&gt;' + sMessage + '&lt;/div&gt;'); } function clearNotification(){ console.log('cleaing notification'); if ($('div.emailMismatch').length !== 0) { $('div.emailMismatch').remove(); $('div.body.editable div.emailHeader').css('background-color',sDefaultBackgroundCSS) } } main(); $('body').on("change", "#sFrom", function(e, data) { var sNew = $('#sFrom &gt; option')[data.ixSelectedOption]; console.log('from has changed to: ' + sNew.innerText); main(sNew.innerText); }); $(window).on('BugViewChange', function(event) { main(); }); }); css: div.emailMismatch{ font-weight: bold; font-size: 120%; } </code></pre>