From b31e9d523990867eaec02b35743754c7f97e7ce7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 11 Dec 2008 14:17:52 -0700 Subject: [PATCH] Optimize address data Don't need 'display' and 'address' entries - we can build these entries from 'inner' and 'personal' data via javascript. Fix display of partslist in popup message window. --- imp/js/DimpCore.js | 2 +- imp/js/src/DimpCore.js | 5 +++-- imp/lib/Views/ShowMessage.php | 33 ++++++++++----------------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/imp/js/DimpCore.js b/imp/js/DimpCore.js index c90c3a88c..1199bfda1 100644 --- a/imp/js/DimpCore.js +++ b/imp/js/DimpCore.js @@ -1 +1 @@ -var frames={horde_main:true},DimpCore={acount:0,remove_gc:[],server_error:0,view_id:1,buttons:["button_reply","button_forward","button_spam","button_ham","button_deleted"],debug:function(a,b){if(!this.is_logout&&DIMP.conf.debug){alert(a+": "+(b instanceof Error?b.name+"-"+b.message:Object.inspect(b)))}},toRangeString:function(a){var b="";$H(a).each(function(f){if(!f.value.size()){return}var d=f.value.numericSort(),e=last=d.shift(),c=[];d.each(function(g){g=Number(g);if(last+1==g){last=g}else{c.push(e+(last==e?"":(":"+last)));e=last=g}});c.push(e+(last==e?"":(":"+last)));b+="{"+f.key.length+"}"+f.key+c.join(",")});return b},parseRangeString:function(g){var e,b,c,f,a={},d=[];g=g.strip();while(!g.blank()){if(!g.startsWith("{")){break}c=g.indexOf("}");e=Number(g.substr(1,c-1));f=g.substr(c+1,e);c+=e+1;b=g.indexOf("{",c);if(b==-1){uidstr=g.substr(c);g=""}else{uidstr=g.substr(c,b-c);g=g.substr(b)}uidstr.split(",").each(function(i){var h=i.split(":");if(h.size()==1){d.push(Number(i))}else{d=d.concat($A($R(Number(h[0]),Number(h[1]))))}});a[f]=d}return a},doAction:function(f,g,e,h,d){var a,c={};if(!this.doActionOpts){this.doActionOpts={onException:function(b,i){this.debug("onException",i)}.bind(this),onFailure:function(b,i){this.debug("onFailure",b)}.bind(this),evalJS:false,evalJSON:true}}d=Object.extend(this.doActionOpts,d||{});g=$H(g);f=f.startsWith("*")?f.substring(1):DIMP.conf.URI_IMP+"/"+f;if(e){if(e.viewport_selection){a=e.getBuffer();if(a.getMetaData("search")){e.get("dataob").each(function(b){if(!c[b.view]){c[b.view]=[]}c[b.view].push(b.imapuid)})}else{c[a.getView()]=e.get("uid")}e=c}g.set("uid",DimpCore.toRangeString(e))}if(DIMP.conf.SESSION_ID){g.update(DIMP.conf.SESSION_ID.toQueryParams())}d.parameters=g.toQueryString();d.onComplete=function(b,i){this.doActionComplete(b,h)}.bind(this);new Ajax.Request(f,d)},doActionComplete:function(b,d){this.inAjaxCallback=true;var a;if(!b.responseJSON){if(++this.server_error==3){this.showNotifications([{type:"horde.error",message:DIMP.text.ajax_timeout}])}this.inAjaxCallback=false;return}a=b.responseJSON;if(!a.msgs){a.msgs=[]}if(a.response&&Object.isFunction(d)){if(DIMP.conf.debug){d(a)}else{try{d(a)}catch(c){}}}if(this.server_error>=3){a.msgs.push({type:"horde.success",message:DIMP.text.ajax_recover})}this.server_error=0;if(!a.msgs_noauto){this.showNotifications(a.msgs)}if(this.onDoActionComplete){this.onDoActionComplete(a)}this.inAjaxCallback=false},setTitle:function(a){document.title=DIMP.conf.name+" :: "+a},showNotifications:function(a){if(!a.size()||this.is_logout){return}a.find(function(d){switch(d.type){case"dimp.timeout":this.is_logout=true;this.redirect(DIMP.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"imp.reply":case"imp.forward":case"imp.redirect":case"dimp.request":case"dimp.sticky":var h,i,k,e,j,f,g=$("alerts"),b=new Element("DIV",{className:d.type.replace(".","-")}),c=d.message;if(!g){g=new Element("DIV",{id:"alerts"});$(document.body).insert(g)}if($w("dimp.request dimp.sticky").indexOf(d.type)==-1){c=c.unescapeHTML().unescapeHTML()}g.insert(b.update(c));if(DIMP.conf.is_ie6){k=new Element("DIV",{className:"ie6alertsfix"}).clonePosition(b,{setLeft:false,setTop:false});h=k;k.insert(b.remove());g.insert(k)}else{h=b}i=Effect.Fade.bind(this,b,{duration:1.5,afterFinish:this.removeAlert.bind(this)});h.observe("click",i);if($w("horde.error dimp.request dimp.sticky").indexOf(d.type)==-1){i.delay(d.type=="horde.warning"?10:3)}if(d.type=="dimp.request"){j=function(){i();document.stopObserving("click",j)};document.observe("click",j)}if(f=$("alertslog")){switch(d.type){case"horde.error":e=DIMP.text.alog_error;break;case"horde.message":e=DIMP.text.alog_message;break;case"horde.success":e=DIMP.text.alog_success;break;case"horde.warning":e=DIMP.text.alog_warning;break}if(e){f=f.down("DIV UL");if(f.down().hasClassName("noalerts")){f.down().remove()}f.insert(new Element("LI").insert(new Element("P",{className:"label"}).insert(e)).insert(new Element("P",{className:"indent"}).insert(c).insert(new Element("SPAN",{className:"alertdate"}).insert("["+(new Date).toLocaleString()+"]"))))}}}},this)},toggleAlertsLog:function(){var a=$("alertsloglink").down("A"),c=$("alertslog").down("DIV"),b={duration:0.5};if(c.visible()){Effect.BlindUp(c,b);a.update(DIMP.text.showalog)}else{Effect.BlindDown(c,b);a.update(DIMP.text.hidealog)}},removeAlert:function(c){try{var a=$(c.element),b=a.up();if(b&&b.parentNode){this.addGC(a.remove());if(!b.childElements().size()&&b.hasClassName("ie6alertsfix")){this.addGC(b.remove())}}}catch(d){this.debug("removeAlert",d)}},compose:function(c,b){var a=DIMP.conf.compose_url;b=b||{};if(c){b.type=c}this.popupWindow(this.addURLParam(a,b),"compose"+new Date().getTime())},popupWindow:function(b,a){if(!(window.open(b,a.replace(/\W/g,"_"),"width="+DIMP.conf.popup_width+",height="+DIMP.conf.popup_height+",status=1,scrollbars=yes,resizable=yes"))){this.showNotifications([{type:"horde.warning",message:DIMP.text.popup_block}])}},closePopup:function(){if(this.inAjaxCallback){this.closePopup.bind(this).defer()}else{window.close()}},logout:function(){this.is_logout=true;this.redirect(DIMP.conf.URI_IMP+"/LogOut")},redirect:function(a){a=this.addSID(a);if(parent.frames.horde_main){parent.location=a}else{window.location=a}},addMouseEvents:function(a){this.DMenu.addElement(a.id,"ctx_"+a.type,a)},removeMouseEvents:function(a){this.DMenu.removeElement($(a).readAttribute("id"));this.addGC(a)},addPopdown:function(b,a){var c=$(b);c.insert({after:$($("popdown_img").cloneNode(false)).writeAttribute("id",b+"_img").show()});this.addMouseEvents({id:b+"_img",type:a,offset:c.up(),left:true})},buildAddressLinks:function(d,a){var e,c,b=d.size();if(b>15){c=$("largeaddrspan").cloneNode(true);a.insert(c);e=c.down(".dispaddrlist");c=c.down();this.clickObserveHandler({d:c,f:function(f){[f.down(),f.down(1),f.next()].invoke("toggle")}.curry(c)});c=c.down();c.setText(c.getText().replace("%d",b))}else{e=a}d.each(function(h,g){var f;if(h.raw){f=h.raw}else{f=new Element("A",{className:"address",id:"addr"+this.acount++,personal:h.personal,email:h.inner,address:h.address}).insert(h.display?h.display:h.address);f.observe("mouseover",function(){f.stopObserving("mouseover");this.addMouseEvents({id:f.id,type:"contacts",offset:f,left:true})}.bind(this))}e.insert(f);if(g+1!=b){e.insert(", ")}},this);return a},removeAddressLinks:function(a){[a.select(".address"),a.select(".largeaddrtoggle")].flatten().compact().each(this.removeMouseEvents.bind(this))},messageOnLoad:function(){var b=this.clickObserveHandler,a;if($("partlist")){b({d:$("partlist_col").up(),f:function(){$("partlist","partlist_col","partlist_exp").invoke("toggle")}})}if(a=$("msg_print")){b({d:a,f:function(){window.print()}})}if(a=$("msg_view_source")){b({d:a,f:function(){view(DimpCore.addSID(DIMP.conf.URI_VIEW)+"&index="+DIMP.conf.msg_index+"&mailbox="+DIMP.conf.msg_folder,DIMP.conf.msg_index+"|"+DIMP.conf.msg_folder)}})}b({d:$("ctx_contacts_new"),f:function(){this.compose("new",{to:this.DMenu.element().readAttribute("address")})}.bind(this),ns:true});b({d:$("ctx_contacts_add"),f:function(){this.doAction("AddContact",{name:this.DMenu.element().readAttribute("personal"),email:this.DMenu.element().readAttribute("email")},null,true)}.bind(this),ns:true});if($("alertslog")){b({d:$("alertsloglink"),f:this.toggleAlertsLog.bind(this)})}},addGC:function(a){this.remove_gc=this.remove_gc.concat(a)},clickObserveHandler:function(a){return a.d.observe("click",DimpCore._clickFunc.curry(a))},_clickFunc:function(b,a){b.p?b.f(a):b.f();if(!b.ns){a.stop()}},addSID:function(a){if(!DIMP.conf.SESSION_ID){return a}return this.addURLParam(a,DIMP.conf.SESSION_ID.toQueryParams())},addURLParam:function(a,c){var b=a.indexOf("?");if(b!=-1){c=$H(a.toQueryParams()).merge(c).toObject();a=a.substring(0,b)}return a+"?"+Object.toQueryString(c)},reloadMessage:function(a){if(typeof DimpFullmessage!="undefined"){window.location=this.addURLParam(document.location.href,a)}else{DimpBase.loadPreview(null,a)}}};if(typeof ContextSensitive!="undefined"){DimpCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.DimpCore){DIMP.baseWindow=parent.opener.DIMP.baseWindow||parent.opener}}catch(a){}if(!DIMP.conf.spam_reporting){DimpCore.buttons=DimpCore.buttons.without("button_spam")}if(!DIMP.conf.ham_reporting){DimpCore.buttons=DimpCore.buttons.without("button_ham")}new PeriodicalExecuter(function(){if(DimpCore.remove_gc.size()){try{$A(DimpCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(b){DimpCore.debug("remove_gc[].stopObserving",b)}}},10)});Event.observe(window,"load",function(){DimpCore.window_load=true});Element.addMethods({setText:function(b,c){var a=0;$A(b.childNodes).each(function(d){if(d.nodeType==3){if(a++){Element.remove(d)}else{d.nodeValue=c}}});if(!a){$(b).insert(c)}},getText:function(b,a){var c="";$A(b.childNodes).each(function(d){if(d.nodeType==3){c+=d.nodeValue}else{if(a&&d.hasChildNodes()){c+=$(d).getText(true)}}});return c}});Object.extend(Array.prototype,{numericSort:function(){return this.sort(function(d,c){if(d>c){return 1}else{if(d=3){a.msgs.push({type:"horde.success",message:DIMP.text.ajax_recover})}this.server_error=0;if(!a.msgs_noauto){this.showNotifications(a.msgs)}if(this.onDoActionComplete){this.onDoActionComplete(a)}this.inAjaxCallback=false},setTitle:function(a){document.title=DIMP.conf.name+" :: "+a},showNotifications:function(a){if(!a.size()||this.is_logout){return}a.find(function(d){switch(d.type){case"dimp.timeout":this.is_logout=true;this.redirect(DIMP.conf.timeout_url);return true;case"horde.error":case"horde.message":case"horde.success":case"horde.warning":case"imp.reply":case"imp.forward":case"imp.redirect":case"dimp.request":case"dimp.sticky":var h,i,k,e,j,f,g=$("alerts"),b=new Element("DIV",{className:d.type.replace(".","-")}),c=d.message;if(!g){g=new Element("DIV",{id:"alerts"});$(document.body).insert(g)}if($w("dimp.request dimp.sticky").indexOf(d.type)==-1){c=c.unescapeHTML().unescapeHTML()}g.insert(b.update(c));if(DIMP.conf.is_ie6){k=new Element("DIV",{className:"ie6alertsfix"}).clonePosition(b,{setLeft:false,setTop:false});h=k;k.insert(b.remove());g.insert(k)}else{h=b}i=Effect.Fade.bind(this,b,{duration:1.5,afterFinish:this.removeAlert.bind(this)});h.observe("click",i);if($w("horde.error dimp.request dimp.sticky").indexOf(d.type)==-1){i.delay(d.type=="horde.warning"?10:3)}if(d.type=="dimp.request"){j=function(){i();document.stopObserving("click",j)};document.observe("click",j)}if(f=$("alertslog")){switch(d.type){case"horde.error":e=DIMP.text.alog_error;break;case"horde.message":e=DIMP.text.alog_message;break;case"horde.success":e=DIMP.text.alog_success;break;case"horde.warning":e=DIMP.text.alog_warning;break}if(e){f=f.down("DIV UL");if(f.down().hasClassName("noalerts")){f.down().remove()}f.insert(new Element("LI").insert(new Element("P",{className:"label"}).insert(e)).insert(new Element("P",{className:"indent"}).insert(c).insert(new Element("SPAN",{className:"alertdate"}).insert("["+(new Date).toLocaleString()+"]"))))}}}},this)},toggleAlertsLog:function(){var a=$("alertsloglink").down("A"),c=$("alertslog").down("DIV"),b={duration:0.5};if(c.visible()){Effect.BlindUp(c,b);a.update(DIMP.text.showalog)}else{Effect.BlindDown(c,b);a.update(DIMP.text.hidealog)}},removeAlert:function(c){try{var a=$(c.element),b=a.up();if(b&&b.parentNode){this.addGC(a.remove());if(!b.childElements().size()&&b.hasClassName("ie6alertsfix")){this.addGC(b.remove())}}}catch(d){this.debug("removeAlert",d)}},compose:function(c,b){var a=DIMP.conf.compose_url;b=b||{};if(c){b.type=c}this.popupWindow(this.addURLParam(a,b),"compose"+new Date().getTime())},popupWindow:function(b,a){if(!(window.open(b,a.replace(/\W/g,"_"),"width="+DIMP.conf.popup_width+",height="+DIMP.conf.popup_height+",status=1,scrollbars=yes,resizable=yes"))){this.showNotifications([{type:"horde.warning",message:DIMP.text.popup_block}])}},closePopup:function(){if(this.inAjaxCallback){this.closePopup.bind(this).defer()}else{window.close()}},logout:function(){this.is_logout=true;this.redirect(DIMP.conf.URI_IMP+"/LogOut")},redirect:function(a){a=this.addSID(a);if(parent.frames.horde_main){parent.location=a}else{window.location=a}},addMouseEvents:function(a){this.DMenu.addElement(a.id,"ctx_"+a.type,a)},removeMouseEvents:function(a){this.DMenu.removeElement($(a).readAttribute("id"));this.addGC(a)},addPopdown:function(b,a){var c=$(b);c.insert({after:$($("popdown_img").cloneNode(false)).writeAttribute("id",b+"_img").show()});this.addMouseEvents({id:b+"_img",type:a,offset:c.up(),left:true})},buildAddressLinks:function(d,a){var e,c,b=d.size();if(b>15){c=$("largeaddrspan").cloneNode(true);a.insert(c);e=c.down(".dispaddrlist");c=c.down();this.clickObserveHandler({d:c,f:function(f){[f.down(),f.down(1),f.next()].invoke("toggle")}.curry(c)});c=c.down();c.setText(c.getText().replace("%d",b))}else{e=a}d.each(function(j,h){var f,g;if(j.raw){f=j.raw}else{g=j.personal?(j.personal+" <"+j.inner+">"):j.inner;f=new Element("A",{className:"address",id:"addr"+this.acount++,personal:j.personal,email:j.inner,address:g}).insert(g.escapeHTML());f.observe("mouseover",function(){f.stopObserving("mouseover");this.addMouseEvents({id:f.id,type:"contacts",offset:f,left:true})}.bind(this))}e.insert(f);if(h+1!=b){e.insert(", ")}},this);return a},removeAddressLinks:function(a){[a.select(".address"),a.select(".largeaddrtoggle")].flatten().compact().each(this.removeMouseEvents.bind(this))},messageOnLoad:function(){var b=this.clickObserveHandler,a;if($("partlist")){b({d:$("partlist_col").up(),f:function(){$("partlist","partlist_col","partlist_exp").invoke("toggle")}})}if(a=$("msg_print")){b({d:a,f:function(){window.print()}})}if(a=$("msg_view_source")){b({d:a,f:function(){view(DimpCore.addSID(DIMP.conf.URI_VIEW)+"&index="+DIMP.conf.msg_index+"&mailbox="+DIMP.conf.msg_folder,DIMP.conf.msg_index+"|"+DIMP.conf.msg_folder)}})}b({d:$("ctx_contacts_new"),f:function(){this.compose("new",{to:this.DMenu.element().readAttribute("address")})}.bind(this),ns:true});b({d:$("ctx_contacts_add"),f:function(){this.doAction("AddContact",{name:this.DMenu.element().readAttribute("personal"),email:this.DMenu.element().readAttribute("email")},null,true)}.bind(this),ns:true});if($("alertslog")){b({d:$("alertsloglink"),f:this.toggleAlertsLog.bind(this)})}},addGC:function(a){this.remove_gc=this.remove_gc.concat(a)},clickObserveHandler:function(a){return a.d.observe("click",DimpCore._clickFunc.curry(a))},_clickFunc:function(b,a){b.p?b.f(a):b.f();if(!b.ns){a.stop()}},addSID:function(a){if(!DIMP.conf.SESSION_ID){return a}return this.addURLParam(a,DIMP.conf.SESSION_ID.toQueryParams())},addURLParam:function(a,c){var b=a.indexOf("?");if(b!=-1){c=$H(a.toQueryParams()).merge(c).toObject();a=a.substring(0,b)}return a+"?"+Object.toQueryString(c)},reloadMessage:function(a){if(typeof DimpFullmessage!="undefined"){window.location=this.addURLParam(document.location.href,a)}else{DimpBase.loadPreview(null,a)}}};if(typeof ContextSensitive!="undefined"){DimpCore.DMenu=new ContextSensitive()}document.observe("dom:loaded",function(){try{if(parent.opener&&parent.opener.location.host==window.location.host&&parent.opener.DimpCore){DIMP.baseWindow=parent.opener.DIMP.baseWindow||parent.opener}}catch(a){}if(!DIMP.conf.spam_reporting){DimpCore.buttons=DimpCore.buttons.without("button_spam")}if(!DIMP.conf.ham_reporting){DimpCore.buttons=DimpCore.buttons.without("button_ham")}new PeriodicalExecuter(function(){if(DimpCore.remove_gc.size()){try{$A(DimpCore.remove_gc.splice(0,75)).compact().invoke("stopObserving")}catch(b){DimpCore.debug("remove_gc[].stopObserving",b)}}},10)});Event.observe(window,"load",function(){DimpCore.window_load=true});Element.addMethods({setText:function(b,c){var a=0;$A(b.childNodes).each(function(d){if(d.nodeType==3){if(a++){Element.remove(d)}else{d.nodeValue=c}}});if(!a){$(b).insert(c)}},getText:function(b,a){var c="";$A(b.childNodes).each(function(d){if(d.nodeType==3){c+=d.nodeValue}else{if(a&&d.hasChildNodes()){c+=$(d).getText(true)}}});return c}});Object.extend(Array.prototype,{numericSort:function(){return this.sort(function(d,c){if(d>c){return 1}else{if(d') : o.inner; + a = new Element('A', { className: 'address', id: 'addr' + this.acount++, personal: o.personal, email: o.inner, address: t }).insert(t.escapeHTML()); a.observe('mouseover', function() { a.stopObserving('mouseover'); this.addMouseEvents({ id: a.id, type: 'contacts', offset: a, left: true }); }.bind(this)); } base.insert(a); diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index 983a1ccd3..e0d90e25f 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -17,8 +17,7 @@ class IMP_Views_ShowMessage * @param array $addrlist The list of addresses from * Horde_Mime_Address::parseAddressList(). * - * @return array Array with the following keys: address, display, inner, - * personal, raw. + * @return array Array with the following keys: inner, personal, raw. */ private function _buildAddressList($addrlist) { @@ -30,28 +29,16 @@ class IMP_Views_ShowMessage $call_hook = !empty($GLOBALS['conf']['dimp']['hooks']['addressformatting']); foreach (Horde_Mime_Address::getAddressesFromObject($addrlist) as $ob) { - if (empty($ob['address']) || empty($ob['inner'])) { - continue; - } - - /* If this is an incomplete e-mail address, don't link to - * anything. */ - if ($call_hook) { - $addr_array[] = array('raw' => Horde::callHook('_imp_hook_dimp_addressformatting', array($ob), 'imp')); - } else { - $tmp = array(); - foreach (array('address', 'display', 'inner', 'personal') as $val) { - if ($val == 'display') { - $ob['display'] = htmlspecialchars($ob['display']); - if ($ob['display'] == $ob['address']) { - continue; - } - } - if (!empty($ob[$val])) { - $tmp[$val] = $ob[$val]; + if (!empty($ob['inner'])) { + if ($call_hook) { + $addr_array[] = array('raw' => Horde::callHook('_imp_hook_dimp_addressformatting', array($ob), 'imp')); + } else { + $tmp = array('inner' => $ob['inner']); + if (!empty($ob['personal'])) { + $tmp['personal'] = $ob['personal']; } + $addr_array[] = $tmp; } - $addr_array[] = $tmp; } } @@ -337,7 +324,7 @@ class IMP_Views_ShowMessage $tmp .= ''; } - $result['atc_list'] = '' . $tmp . '
'; + $result['atc_list'] = $tmp; } if ($preview && !empty($GLOBALS['conf']['dimp']['hooks']['previewview'])) { -- 2.11.0