Ext.namespace("Zarafa.plugins.smime.data");Zarafa.plugins.smime.data.JsonCertificateReader=Ext.extend(Zarafa.core.data.JsonReader,{customObjectType:Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,constructor:function(a,b){a=Ext.applyIf(a||{},{dynamicRecord:!1});b=Zarafa.core.data.RecordFactory.getRecordClassByCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME);Zarafa.plugins.smime.data.JsonCertificateReader.superclass.constructor.call(this,a,b)}});Ext.namespace("Zarafa.plugins.smime.data");
Zarafa.plugins.smime.data.SmimeAttachmentRecordFields=[{name:"cert",type:"boolean",defaultValue:!1},{name:"cert_message",type:"string"},{name:"cert_warning",type:"string"}];Zarafa.core.data.RecordCustomObjectType.addProperty("ZARAFA_SMIME_ATTACHMENT");Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME_ATTACHMENT,Zarafa.plugins.smime.data.SmimeAttachmentRecord);
Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME_ATTACHMENT,Zarafa.plugins.smime.data.SmimeAttachmentRecordFields);Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME_ATTACHMENT,Zarafa.core.data.IPMAttachmentRecordFields);Ext.namespace("Zarafa.plugins.smime.data");
Zarafa.plugins.smime.data.SmimeAttachmentStore=Ext.extend(Zarafa.core.data.IPMAttachmentStore,{attachmentRecordType:Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME_ATTACHMENT,constructor:function(a){a=a||{};Zarafa.plugins.smime.data.SmimeAttachmentStore.superclass.constructor.call(this,a)}});Ext.reg("smime.attachmentstore",Zarafa.plugins.smime.data.SmimeAttachmentStore);Ext.namespace("Zarafa.plugins.smime.data");
Zarafa.plugins.smime.data.SmimeCertificateRecordFields=[{name:"entryid",type:"string"},{name:"type",type:"string"},{name:"issued_by",type:"string"},{name:"issued_to",type:"string"},{name:"serial",type:"string"},{name:"email",type:"string",defaultValue:""},{name:"validto",type:"date",dateFormat:"timestamp",defaultValue:null},{name:"validfrom",type:"date",dateFormat:"timestamp",defaultValue:null},{name:"fingerprint_sha1",type:"string"},{name:"fingerprint_md5",type:"string"}];
Zarafa.plugins.smime.data.SmimeCertificateRecord=Ext.extend(Zarafa.core.data.IPMRecord,{});Zarafa.core.data.RecordCustomObjectType.addProperty("ZARAFA_SMIME");Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,Zarafa.plugins.smime.data.SmimeCertificateRecordFields);Zarafa.core.data.RecordFactory.addFieldToCustomType(Zarafa.core.data.RecordCustomObjectType.MAPI_SMIME_ATTACH,Zarafa.core.data.IPMRecordFields);
Zarafa.core.data.RecordFactory.setSubStoreToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,"attachments",Zarafa.plugins.smime.data.SmimeAttachmentStore);Zarafa.core.data.RecordFactory.addListenerToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,"createphantom",function(a){a.afterOpen()});Zarafa.core.data.RecordFactory.setBaseClassToCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,Zarafa.plugins.smime.data.SmimeCertificateRecord);Ext.namespace("Zarafa.plugins.smime.data");
Zarafa.plugins.smime.data.SmimeCertificateStore=Ext.extend(Zarafa.core.data.ListModuleStore,{constructor:function(a){a=a||{};Ext.applyIf(a,{autoLoad:!0,remoteSort:!1,reader:new Zarafa.plugins.smime.data.JsonCertificateReader,writer:new Zarafa.core.data.JsonWriter,proxy:new Zarafa.core.data.IPMProxy({listModuleName:"pluginsmimemodule",itemModuleName:"pluginsmimemodule"})});Zarafa.plugins.smime.data.SmimeCertificateStore.superclass.constructor.call(this,a)}});Ext.reg("smime.certificatestore",Zarafa.plugins.smime.data.SmimeCertificateStore);
Ext.namespace("Zarafa.plugins.smime.data");Zarafa.plugins.smime.data.SmimeResponseHandler=Ext.extend(Zarafa.core.data.AbstractResponseHandler,{successCallback:null,doCertificate:function(a){this.successCallback(a)},doPassphrase:function(a){this.successCallback(a)},doChangepassphrase:function(a){this.successCallback(a)}});Ext.reg("smime.responsehandler",Zarafa.plugins.smime.data.SmimeResponseHandler);Ext.namespace("Zarafa.plugins.smime.dialogs");
Zarafa.plugins.smime.dialogs.ChangePassphraseContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};a=Ext.applyIf(a,{layout:"fit",title:_("Change passphrase"),width:300,height:250,stateful:!1,xtype:"smime.changepassphrasecontentpanel",items:[{xtype:"smime.changepassphrasepanel",buttonAlign:"center",buttons:[{text:_("Change passphrase"),handler:this.onChangePassphrase,scope:this},{text:_("Cancel"),handler:this.close,scope:this}]}]});Zarafa.plugins.smime.dialogs.ChangePassphraseContentPanel.superclass.constructor.call(this,
a)},onChangePassphrase:function(){var a=this.get(0);a.validatePassphrase()&&a.changePassphrasePanel()}});Ext.reg("smime.changepassphrasecontentpanel",Zarafa.plugins.smime.dialogs.ChangePassphraseContentPanel);Ext.namespace("Zarafa.plugins.smime.dialogs");
Zarafa.plugins.smime.dialogs.ChangePassphrasePanel=Ext.extend(Ext.Panel,{constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"smime.changepassphrasepanel",layout:"form",border:!1,header:!1,items:[{hideLabel:!0,xtype:"displayfield",value:_("Old passphrase")},{hideLabel:!0,xtype:"textfield",inputType:"password",anchor:"100%",ref:"old_passphrase",listeners:{change:this.resetVerification,scope:this}},{hideLabel:!0,hidden:!0,hideMode:"visibility",xtype:"displayfield",ref:"wrong_passphrase",cls:"zarafa-smime-invalid-text",
value:_("Wrong passphrase. Please try again")},{hideLabel:!0,xtype:"displayfield",value:_("New passphrase")},{hideLabel:!0,xtype:"textfield",inputType:"password",anchor:"100%",listeners:{change:this.resetVerification,scope:this},ref:"new_passphrase"},{hideLabel:!0,xtype:"displayfield",value:_("Confirm new passphrase")},{hideLabel:!0,xtype:"textfield",inputType:"password",anchor:"100%",listeners:{change:this.resetVerification,scope:this},ref:"confirm_new_passphrase"},{hideLabel:!0,hidden:!0,xtype:"displayfield",
ref:"wrong_verification",cls:"zarafa-smime-invalid-text",value:_("The passphrases don't match. Please try again")}]});Zarafa.plugins.smime.dialogs.ChangePassphrasePanel.superclass.constructor.call(this,a)},validatePassphrase:function(){if(this.new_passphrase.getValue()!==this.confirm_new_passphrase.getValue())return this.wrong_verification.show(),!1;this.wrong_verification.hidden||this.wrong_verification.hide();return!0},resetVerification:function(){this.wrong_verification.hide();this.wrong_passphrase.hide()},
changePassphrasePanel:function(){container.getRequest().singleRequest("pluginsmimemodule","changepassphrase",{passphrase:this.old_passphrase.getValue(),new_passphrase:this.new_passphrase.getValue()},new Zarafa.plugins.smime.data.SmimeResponseHandler({successCallback:this.onChangePassphraseRequest.createDelegate(this)}))},onChangePassphraseRequest:function(a){a.code===Zarafa.plugins.smime.CHANGE_CERTIFICATE_SUCCESS?(container.getNotifier().notify("info.saved",_("S/MIME Message"),_("Passphrase changed succesfully")),
this.dialog.close()):this.wrong_passphrase.show()}});Ext.reg("smime.changepassphrasepanel",Zarafa.plugins.smime.dialogs.ChangePassphrasePanel);Ext.namespace("Zarafa.plugins.smime.dialogs");
Zarafa.plugins.smime.dialogs.PassphraseContentPanel=Ext.extend(Zarafa.core.ui.ContentPanel,{constructor:function(a){a=a||{};a=Ext.applyIf(a,{xtype:"smime.passphrasecontentpanel",cls:"zarafa-smime-passphrasewindow",modal:!0,layout:"fit",title:_("S/MIME Passphrase"),width:350,height:100,stateful:!1,items:[{xtype:"smime.passphrasewindow",ref:"passphrasePanel",record:a.record}]});Zarafa.plugins.smime.dialogs.PassphraseContentPanel.superclass.constructor.call(this,a)}});
Ext.reg("smime.passphrasecontentpanel",Zarafa.plugins.smime.dialogs.PassphraseContentPanel);Ext.namespace("Zarafa.plugins.smime.dialogs");
Zarafa.plugins.smime.dialogs.PassphraseWindow=Ext.extend(Ext.Panel,{btn:void 0,constructor:function(a){a=a||{};this.btn=a.record;Ext.applyIf(a,{xtype:"smime.passphrasewindow",layout:"fit",border:!1,items:this.getInnerItems(),buttons:[{type:"submit",text:_("Submit"),cls:"zarafa-action passphrase_submit",handler:this.checkPassphrase,scope:this},{text:_("Cancel"),cls:"passphrase_cancel",handler:this.onCancel,scope:this}],listeners:{scope:this,beforedestroy:this.onBeforeDestroy}});Zarafa.plugins.smime.dialogs.PassphraseWindow.superclass.constructor.call(this,
a)},getInnerItems:function(){var a=[],b=container.getSettingsModel().get("zarafa/v1/plugins/smime/passphrase_cache");Ext.isGecko&&b?(b=container.getBaseURL(),b=Ext.urlAppend(b,"load=custom&name=smime_passphrase"),a.push({xtype:"box",autoEl:{tag:"iframe",style:"border-width: 0px; height:100%; width:100%",src:b},listeners:{render:this.onIframeRendered,scope:this}})):a.push(this.createForm());return a},onBeforeDestroy:function(){if(Ext.isDefined(this.windowName)){var a=this.getEl().dom.ownerDocument.defaultView;
Zarafa.core.BrowserWindowMgr.unRegister(this.windowName);Zarafa.core.BrowserWindowMgr.setActive(a.name)}},onCancel:function(){this.dialog.close()},onIframeRendered:function(a){var b=Ext.isDefined(a.getEl)?a.el:a;Ext.EventManager.on(b,"load",function(){this.windowName="smime-passphrasewindow-"+Zarafa.plugins.smime.dialogs.PassphraseWindow.iframeCounter++;b.dom.contentWindow.name=this.windowName;Zarafa.core.BrowserWindowMgr.browserWindows.add(this.windowName,b.dom.contentWindow);Zarafa.core.BrowserWindowMgr.setActive(this.windowName);
Zarafa.core.BrowserWindowMgr.initExtCss(b.dom.contentWindow);Ext.getBody().on("contextmenu",Zarafa.core.BrowserWindowMgr.onBodyContextMenu,this);new Zarafa.plugins.smime.ui.Viewport({layout:"fit",cls:"k-smime-viewport",body:b.dom.contentDocument.body,items:[this.createForm()]})},this)},createForm:function(){var a=container.getSettingsModel().get("zarafa/v1/plugins/smime/passphrase_cache");return{xtype:a?"smime.form":"panel",url:Ext.urlAppend(container.getBaseURL(),"load=custom&name=smime_passphrasecheck"),
method:"POST",border:!1,layout:"form",items:[{xtype:"textfield",inputType:"text",cls:"username",name:"username",hidden:!0,value:container.getUser().getSMTPAddress()},{xtype:"textfield",inputType:"password",cls:"certificate_passphrase",defaultAutoCreate:{tag:"input",type:"password",size:"20",autocomplete:a?"on":"nope",placeholder:_("Certificate passphrase")},name:"spassword",hideLabel:!0,anchor:"100%",listeners:{scope:this,afterrender:this.onAfterRenderPasswordField,specialkey:this.onSpecialKey}},
{xtype:"button",type:"submit",hidden:!0,ref:"submitBtn"}],listeners:{scope:this,afterrender:function(b){this.formPanel=b}}}},onAfterRenderPasswordField:function(a){this.passphrase=a;setTimeout(function(){a.focus()},500);var b=this.getEl().dom.ownerDocument.defaultView;Zarafa.core.BrowserWindowMgr.setActive(b.name);b.addEventListener("unload",function(){this.onBeforeDestroy()}.bind(this))},onSpecialKey:function(a,b){b.getKey()===b.ENTER&&this.checkPassphrase(a)},checkPassphrase:function(){var a=container.getUser();
container.getRequest().singleRequest("pluginsmimemodule","passphrase",{user:a.getSMTPAddress(),passphrase:this.passphrase.getValue()},new Zarafa.plugins.smime.data.SmimeResponseHandler({successCallback:this.onPassphraseCallback.createDelegate(this)}))},onPassphraseCallback:function(a){a.status?(this.btn instanceof Zarafa.core.data.IPMRecord?this.btn.open({forceLoad:!0}):(a=this.btn.ownerCt.record,a||(a=this.btn.parentMenu.ownerCt.ownerCt.dialog.record),a.set("message_class",this.btn.message_class),
a.save(),this.btn.setIconClass("icon_smime_sign_selected")),"smime.form"===this.formPanel.getXType()&&this.formPanel.submitBtn.getEl().down("div").down("em").down("button").dom.click(),this.dialog.close()):(this.passphrase&&this.passphrase.reset(),container.getNotifier().notify("error.connection",_("S/MIME Message"),_("The passphrase you typed is incorrect. Please try again.")))}});Ext.reg("smime.passphrasewindow",Zarafa.plugins.smime.dialogs.PassphraseWindow);
Zarafa.plugins.smime.dialogs.PassphraseWindow.iframeCounter=0;Ext.namespace("Zarafa.plugins.smime.ui");Zarafa.plugins.smime.ui.FormPanel=Ext.extend(Ext.FormPanel,{constructor:function(a){a=a||{};Ext.apply(a,{xtype:"smime.form"});Zarafa.plugins.smime.ui.FormPanel.superclass.constructor.call(this,a)},initComponent:function(){Zarafa.plugins.smime.ui.FormPanel.superclass.initComponent.apply(this,arguments);Ext.applyIf(this.bodyCfg,{action:this.url})}});Ext.reg("smime.form",Zarafa.plugins.smime.ui.FormPanel);
Ext.namespace("Zarafa.plugins.smime.ui");Ext.apply(Ext.EventManager,function(){var a,b,c,e;return{doIframeResizeEvent:function(d){var f=Ext.get(d.document.body);d=f.getHeight();f=f.getWidth();c==d&&e==f||a.fire(e=f,c=d)},onIframeResize:function(d,f,g){a&&a.clearListeners();a=new Ext.util.Event;b=new Ext.util.DelayedTask(this.doIframeResizeEvent,this,[g.window]);Ext.EventManager.on(g.window,"resize",this.fireIframeResize,this);a.addListener(d,f,g)},fireIframeResize:function(){a&&b.delay(100)}}}());
Zarafa.plugins.smime.ui.Viewport=Ext.extend(Ext.Viewport,{body:null,initComponent:function(){Ext.Viewport.superclass.initComponent.call(this);this.body instanceof Ext.Element||(this.body=Ext.get(this.body));var a=this.body.dom.ownerDocument,b=a.defaultView;a.getElementsByTagName("html")[0].className+=" x-viewport";this.el=this.body;this.el.setHeight=Ext.emptyFn;this.el.setWidth=Ext.emptyFn;this.el.setSize=Ext.emptyFn;this.el.dom.scroll="no";this.allowDomMove=!1;this.autoHeight=this.autoWidth=!0;Ext.EventManager.onIframeResize(this.fireResize,
this,{window:b});this.renderTo=this.el}});Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.PublickeyGrid=Ext.extend(Ext.grid.GridPanel,{constructor:function(a){a=a||{};a.store||(a.store=new Zarafa.plugins.smime.data.SmimeCertificateStore);Ext.applyIf(a,{xtype:"smime.publickeygrid",store:a.store,viewConfig:{forceFit:!0,deferEmptyText:!1,emptyText:"<div class='emptytext'>"+_("No certificates imported, please upload your private certificate")+"</div>"},loadMask:this.initLoadMask(),columns:this.initColumnModel(),selModel:this.initSelectionModel(),listeners:{viewready:this.onViewReady,
scope:this}});Zarafa.plugins.smime.settings.PublickeyGrid.superclass.constructor.call(this,a)},initEvents:function(){Zarafa.plugins.smime.settings.PublickeyGrid.superclass.initEvents.call(this);this.mon(this.store,"load",this.onViewReady,this,{single:!0})},initColumnModel:function(){return[{dataIndex:"email",header:_("Email"),sortable:!0,renderer:Ext.util.Format.htmlEncode},{dataIndex:"validfrom",sortable:!0,header:_("Valid from"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"validto",sortable:!0,
header:_("Expires"),renderer:Ext.util.Format.htmlEncode},{dataIndex:"type",sortable:!0,header:_("Type"),renderer:Ext.util.Format.htmlEncode}]},initSelectionModel:function(){return new Ext.grid.RowSelectionModel({singleSelect:!0})},initLoadMask:function(){return{msg:_("Loading certificates")+"..."}},onViewReady:function(){this.getSelectionModel().selectFirstRow()},removeCertificate:function(){var a=this.getSelectionModel().getSelected();if(a)if("private"===a.get("type"))Ext.MessageBox.show({title:_("S/MIME Plugin"),
msg:_("Do you really want to remove your private certificate? If you remove your certificate you will not be able to sign or decrypt S/MIME emails."),icon:Ext.MessageBox.WARNING,fn:this.onRemoveCertificate,scope:this,buttons:Ext.MessageBox.YESNO});else this.onRemoveCertificateHelper();else Ext.MessageBox.show({title:_("S/MIME Plugin"),msg:_("Please select a certificate."),buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO})},onRemoveCertificate:function(a){if("yes"===a)this.onRemoveCertificateHelper()},
onRemoveCertificateHelper:function(){var a=this.getSelectionModel(),b=a.getSelected();a.hasNext()?a.selectNext():a.hasPrevious()&&a.selectPrevious();this.store.remove(b)},showDetails:function(){var a=this.getSelectionModel().getSelected();Ext.isDefined(a)&&(a="Email: "+a.get("email")+"</br>Serial: "+a.get("serial")+"</br>Issued by: "+a.get("issued_by")+"</br>Issued to: "+a.get("issued_to")+"</br>SHA1 Fingerprint: "+a.get("fingerprint_sha1")+"</br>MD5 Fingerprint: "+a.get("fingerprint_md5")+"</br>",
Ext.Msg.alert(_("Certificate details"),a))}});Ext.reg("smime.publickeygrid",Zarafa.plugins.smime.settings.PublickeyGrid);Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.SettingsPublickeyPanel=Ext.extend(Ext.Panel,{store:void 0,loadMask:void 0,constructor:function(a){a=a||{};a.store||(a.store=new Zarafa.plugins.smime.data.SmimeCertificateStore);Ext.applyIf(a,{xtype:"smime.publiccertificatespanel",border:!1,layout:{type:"vbox",align:"stretch",pack:"start"},items:this.createPanelItems(a.store)});Zarafa.plugins.smime.settings.SettingsPublickeyPanel.superclass.constructor.call(this,a)},createPanelItems:function(a){return[{xtype:"displayfield",
value:_("Below you can view and delete public & private certificate(s) stored on the server."),fieldClass:"x-form-display-field zarafa-settings-widget-extrainfo"},{xtype:"container",flex:1,layout:{type:"hbox",align:"stretch",pack:"start"},items:[{xtype:"smime.publickeygrid",ref:"../publickeyGrid",store:a,flex:1},{xtype:"container",width:160,defaults:{width:140},layout:{type:"vbox",align:"center",pack:"start"},items:[{xtype:"displayfield",value:_("Filter on Email")},{xtype:"textfield",listeners:{specialkey:function(b,
c){c.getKey()==c.ENTER&&a.filter("email",b.getValue())}}},{xtype:"spacer",height:20},{xtype:"button",width:84,text:_("Remove"),disabled:!0,ref:"../../removeButton",handler:this.onCertificateRemove,scope:this},{xtype:"spacer",height:20},{xtype:"button",width:84,text:_("Details"),disabled:!0,ref:"../../detailButton",handler:this.onDetailButton,scope:this}]}]}]},initEvents:function(){Zarafa.plugins.smime.settings.SettingsPublickeyPanel.superclass.initEvents.call(this);this.mon(this.publickeyGrid.getSelectionModel(),
"selectionchange",this.onGridSelectionChange,this)},showLoadMask:function(){this.loadMask||(this.loadMask=new Zarafa.common.ui.LoadMask(this.el));this.loadMask.show()},hideLoadMask:function(){this.loadMask&&this.loadMask.hide()},onGridSelectionChange:function(a){a=!1===a.hasSelection();this.removeButton.setDisabled(a);this.detailButton.setDisabled(a)},onCertificateRemove:function(){this.publickeyGrid.removeCertificate()},onDetailButton:function(){this.publickeyGrid.showDetails()},discardChanges:function(){this.store.load()},
saveChanges:function(){this.store.save()}});Ext.reg("smime.publiccertificatespanel",Zarafa.plugins.smime.settings.SettingsPublickeyPanel);Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.SettingsPublickeyWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{constructor:function(a){a=a||{};Ext.applyIf(a,{height:400,title:_("Public & Private certificates"),xtype:"smime.settingspublickeysmimewidget",layout:{type:"fit"},items:[{xtype:"smime.publiccertificatespanel",ref:"certificatesPanel",store:a.store}]});Zarafa.plugins.smime.settings.SettingsPublickeyWidget.superclass.constructor.call(this,a)},getCertificateStore:function(){return this.certificatesPanel.store},
initEvents:function(){Zarafa.plugins.smime.settings.SettingsPublickeyWidget.superclass.initEvents.call(this);var a=this.settingsContext.getModel();this.mon(a,"savesettings",this.onSaveSettings,this);this.mon(a,"discardsettings",this.onDiscardSettings,this);this.mon(this.getCertificateStore(),{remove:this.doStoreRemove,update:this.doStoreUpdate,scope:this})},doStoreRemove:function(a,b){b.phantom||this.settingsContext.getModel().setDirty()},doStoreUpdate:function(a,b,c){c!==Ext.data.Record.COMMIT&&
this.settingsContext.getModel().setDirty()},onSaveSettings:function(){this.certificatesPanel.saveChanges()},onDiscardSettings:function(){this.certificatesPanel.discardChanges()}});Ext.reg("smime.settingspublickeywidget",Zarafa.plugins.smime.settings.SettingsPublickeyWidget);Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.SettingsSmimeCategory=Ext.extend(Zarafa.settings.ui.SettingsCategory,{constructor:function(a){a=a||{};this.store=new Zarafa.plugins.smime.data.SmimeCertificateStore;Ext.applyIf(a,{title:_("S/MIME"),categoryIndex:1,iconCls:"icon_smime_settings",items:[{xtype:"smime.settingssmimewidget",store:this.store},{xtype:"smime.uploadcertificatewidget",store:this.store},{xtype:"smime.settingspublickeywidget",settingsContext:a.settingsContext,store:this.store}]});Zarafa.plugins.smime.settings.SettingsSmimeCategory.superclass.constructor.call(this,
a)},onHide:function(){Zarafa.plugins.smime.settings.SettingsSmimeCategory.superclass.onHide.apply(this,arguments);this.mun(this.store,"beforesave",this.onBeforeSaveCertificate,this)},onBeforeSaveSettingsModel:function(){Zarafa.plugins.smime.settings.SettingsSmimeCategory.superclass.onBeforeSaveSettingsModel.apply(this,arguments);this.mon(this.store,"beforesave",this.onBeforeSaveCertificate,this,{single:!0})},onBeforeSaveCertificate:function(){this.displaySavingMask();this.mon(this.store,"save",this.onCertificateSave,
this)},onCertificateSave:function(){this.hideSavingMask(!0);this.mun(this.store,"save",this.onCertificateSave,this)}});Ext.reg("smime.settingssmimecategory",Zarafa.plugins.smime.settings.SettingsSmimeCategory);Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.SettingsSmimeWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{record:void 0,defaultButtonLabel:_("You don't have a valid certificate corresponding to your account"),constructor:function(a){a=a||{};a.store||(a.store=new Zarafa.plugins.smime.data.SmimeCertificateStore);Ext.applyIf(a,{title:_("Personal certificate"),layout:"form",xtype:"smime.settingssmimewidget",items:[{xtype:"button",text:_("Change passphrase for last certificate"),labelStyle:"width:580px",ref:"certificateField",
fieldLabel:this.defaultButtonLabel,labelSeparator:"",handler:this.changePassphrase}]});Zarafa.plugins.smime.settings.SettingsSmimeWidget.superclass.constructor.call(this,a)},initEvents:function(){Zarafa.plugins.smime.settings.SettingsSmimeWidget.superclass.initEvents.call(this);this.mon(this.store,"load",this.onStoreReady,this);this.mon(this.store,"remove",this.onStoreReady,this);this.onStoreReady()},onStoreReady:function(){var a=this.store.findExact("type","private");-1===a?(this.certificateField.disable(),
this.setCertificateButtonLabel(this.defaultButtonLabel)):(this.certificateField.enable(),this.record=this.store.getAt(a),this.setCertificateButtonLabel(_("You have a valid certificate corresponding to your account")))},setCertificateButtonLabel:function(a){this.certificateField.rendered?this.certificateField.label.update(a):this.certificateField.fieldLabel=a},changePassphrase:function(){Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["plugin.smime.dialog.changepassphrasecontentpanel"],
void 0,{modal:!0})}});Ext.reg("smime.settingssmimewidget",Zarafa.plugins.smime.settings.SettingsSmimeWidget);Ext.namespace("Zarafa.plugins.smime.settings");
Zarafa.plugins.smime.settings.UploadCertificateWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{form:void 0,files:void 0,record:void 0,constructor:function(a){a=a||{};a.store||(a.store=new Zarafa.plugins.smime.data.SmimeCertificateStore);Ext.applyIf(a,{title:_("Upload your certificate"),layout:"form",xtype:"smime.uploadcertificatewidget",items:[{xtype:"displayfield",hideLabel:!0,value:_("Below you can upload your private certificate in PKCS#12 format. grommunio Web only accepts certificates which are valid and only stores one private certificate on the server.")},
{xtype:"button",text:_("Select"),defaultValue:_("Select"),iconCls:"icon_smime_settings",fieldLabel:_("Private certificate"),ref:"certificate",width:84,handler:this.selectCertificate,scope:this},{xtype:"textfield",inputType:"password",fieldLabel:_("Certificate passphrase"),width:200,ref:"passphrase",scope:this},{xtype:"button",text:_("Upload"),width:84,handler:this.uploadCertificate,scope:this}]});Zarafa.plugins.smime.settings.UploadCertificateWidget.superclass.constructor.call(this,a)},selectCertificate:function(){this.record=
Zarafa.core.data.RecordFactory.createRecordObjectByCustomType(Zarafa.core.data.RecordCustomObjectType.ZARAFA_SMIME,{});(new Zarafa.common.attachment.ui.UploadAttachmentComponent({callback:this.selectCertificateCallback,scope:this})).openAttachmentDialog()},uploadCertificate:function(){if(Ext.isEmpty(this.passphrase.getValue()))Ext.MessageBox.show({title:_("S/MIME Plugin"),msg:_("You must fill in the certificate passphrase to upload your certificate."),buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO});
else if(Ext.isEmpty(this.files))Ext.MessageBox.show({title:_("S/MIME Plugin"),msg:_("You must first select a valid private certificate in PKCS#12 format."),buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.INFO});else{var a=this.record.getAttachmentStore();this.mon(a,"update",this.onUpdate,this);var b={sourcetype:"certificate",passphrase:this.passphrase.getValue()};a.uploadFiles(this.files,this.form,!0,b)}},selectCertificateCallback:function(a,b){this.certificate.setText(a[0].name);this.files=a;this.form=
b},onUpdate:function(a,b){b.get("cert")?(container.getNotifier().notify("info.saved",_("S/MIME Message"),b.get("cert_warning")),this.store.load(),this.passphrase.reset(),this.certificate.setText(this.certificate.defaultValue)):container.getNotifier().notify("error.connection",_("S/MIME Message"),b.get("cert_warning"))},update:function(){this.passphrase.reset();this.certificate.setText(this.certificate.defaultValue)}});Ext.reg("smime.uploadcertificatewidget",Zarafa.plugins.smime.settings.UploadCertificateWidget);
Ext.namespace("Zarafa.plugins.smime");
Zarafa.plugins.smime.SmimePlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.smime.SmimePlugin.superclass.initPlugin.apply(this,arguments);this.registerInsertionPoint("context.mail.mailcreatecontentpanel.toolbar.options",this.showSignButton,this);this.registerInsertionPoint("context.mail.mailcreatecontentpanel.toolbar.options",this.showEncryptButton,this);this.registerInsertionPoint("context.settings.categories",this.createSettingsCategories,this);this.registerInsertionPoint("previewpanel.toolbar.detaillinks",
this.showSmimeInfo,this);this.registerInsertionPoint("context.mail.gridrow",this.showMessageClass,this);this.registerInsertionPoint("context.mail.griddefaultcolumn",this.showDefaultColumn,this);Zarafa.core.data.SharedComponentType.addProperty("plugin.smime.dialog.passphrasewindow");Zarafa.core.data.SharedComponentType.addProperty("plugin.smime.dialog.changepassphrasecontentpanel")},createSettingsCategories:function(a,b,c){return[{xtype:"smime.settingssmimecategory",settingsContext:c}]},showSmimeInfo:function(){return{xtype:"button",
plugins:["zarafa.recordcomponentupdaterplugin"],autoEl:{tag:"div",ref:"smimeInfoBox"},scope:this,update:this.onSmimeInfo,handler:this.onSmimeButton}},showSignButton:function(){return{xtype:"button",text:_("Sign"),tooltip:{title:_("Sign message"),text:_("Ensure the authenticity of the message by adding a digital signature to this message. Any changes to the message will invalidate the signature.")},iconCls:"icon_smime_sign",listeners:{afterrender:this.onAfterRenderSmimeButton,beforeshow:this.onAfterRenderSmimeButton,
scope:this},handler:this.onSignButton,scope:this}},showEncryptButton:function(){return{xtype:"button",text:_("Encrypt"),tooltip:{title:_("Encrypt message"),text:_("Ensure the privacy of the message by encrypting its contents. Only the recipient of the message will be able to open it.")},iconCls:"icon_smime_encrypt",listeners:{afterrender:this.onAfterRenderSmimeButton,beforeshow:this.onAfterRenderSmimeButton,scope:this},handler:this.onEncryptButton,scope:this}},onAfterRenderSmimeButton:function(a){switch(this.getRespectiveDialog(a).record.get("message_class")){case "IPM.Note.SMIME":"icon_smime_encrypt"===
a.iconCls&&a.setIconClass("icon_smime_encrypt_selected");break;case "IPM.Note.SMIME.MultipartSigned":"icon_smime_sign"===a.iconCls&&a.setIconClass("icon_smime_sign_selected");break;case "IPM.Note.SMIME.SignedEncrypt":"icon_smime_sign"===a.iconCls?a.setIconClass("icon_smime_sign_selected"):a.setIconClass("icon_smime_encrypt_selected")}},onSmimeButton:function(a){var b=a.record.get("smime");if(a.record.isOpened()&&b)switch(b.type){case "encrypted":b.success!==Zarafa.plugins.smime.SMIME_STATUS_GOOD&&
(b=container.getUser(),container.getRequest().singleRequest("pluginsmimemodule","certificate",{user:b.getSMTPAddress()},new Zarafa.plugins.smime.data.SmimeResponseHandler({successCallback:this.onCertificateCallback.createDelegate(a.record)})));break;case "signed":case "encryptsigned":container.getNotifier().notify(Zarafa.plugins.smime.SmimeText.getPopupStatus(b.success),_("What's going on with my email?"),Zarafa.plugins.smime.SmimeText.getPopupText(b.info))}},onSmimeInfo:function(a){this.record=a;
var b=this.getEl();b.update("");b.removeClass("smime-info-good");b.removeClass("smime-info-fatal");b.removeClass("smime-info-partial");b.removeClass("smime-info-info");var c=a.get("smime");if(a.isOpened()&&c){var e=a.getSender();b.addClass(Zarafa.plugins.smime.SmimeText.getStatusMessageClass(c.success));var d=Zarafa.plugins.smime.SmimeText.getMessageInfo(c.info),f=c.info===Zarafa.plugins.smime.SMIME_DECRYPT_SUCCESS;switch(c.type){case "encrypted":c.success===Zarafa.plugins.smime.SMIME_STATUS_BAD?
b.update('<div class="icon_smime_encr_content"></div> '+d):(c=f?"icon_smime_decr_content":"icon_smime_encr_content",b.update(String.format(' {0} &lt{1}&gt <div class="{2}"></div> {3}',e.get("display_name"),e.get("smtp_address"),c,d)),this.ownerCt.findByType("zarafa.attachmentlinks")[0].update(a,!0));break;case "signed":b.update(String.format('{0} &lt{1}&gt <div class="icon_smime_sign_content"></div> {2}',e.get("display_name"),e.get("smtp_address"),d));break;case "encryptsigned":b.update(String.format('{0} &lt{1}&gt <div class="icon_smime_sign_content"></div> <div class="icon_smime_decr_content"></div> {2}',
e.get("display_name"),e.get("smtp_address"),d)),c.success!==Zarafa.plugins.smime.SMIME_STATUS_BAD&&this.ownerCt.findByType("zarafa.attachmentlinks")[0].update(a,!0)}}},onBeforeSendRecord:function(a,b){var c=[{email:container.getUser().getSMTPAddress(),internal:!0,username:container.getUser().getEmailAddress()}];b.getRecipientStore().each(function(e){const d=e.get("address_type");c.push({email:e.get("smtp_address"),internal:"ZARAFA"===d||"EX"===d,username:e.get("email_address")})},this);a.record.set("smime",
c);return!0},onEncryptButton:function(a){var b=this.getRespectiveDialog(a),c=b.record;if(c){switch(c.get("message_class")){case "IPM.Note.SMIME.MultipartSigned":c.set("message_class","IPM.Note.SMIME.SignedEncrypt");a.setIconClass("icon_smime_encrypt_selected");b.on("beforesendrecord",this.onBeforeSendRecord,this);break;case "IPM.Note":a.setIconClass("icon_smime_encrypt_selected");c.set("message_class","IPM.Note.SMIME");b.on("beforesendrecord",this.onBeforeSendRecord,this);break;case "IPM.Note.SMIME":case "IPM.Note.SMIME.SignedEncrypt":"IPM.Note.SMIME.SignedEncrypt"===
c.get("message_class")?c.set("message_class","IPM.Note.SMIME.MultipartSigned"):c.set("message_class","IPM.Note"),a.setIconClass("icon_smime_encrypt"),c.set("smime",""),c.actions={},b.un("beforesendrecord",this.onBeforeSendRecord,this)}b.saveRecord()}},onSignButton:function(a){var b=this.getRespectiveDialog(a),c=b.record;if(c){var e=this,d=container.getUser(),f=function(){container.getRequest().singleRequest("pluginsmimemodule","certificate",{user:d.getSMTPAddress()},new Zarafa.plugins.smime.data.SmimeResponseHandler({successCallback:e.onCertificateCallback.createDelegate(a)}))};
switch(c.get("message_class")){case "IPM.Note":a.message_class="IPM.Note.SMIME.MultipartSigned";f();break;case "IPM.Note.SMIME":a.message_class="IPM.Note.SMIME.SignedEncrypt";f();break;case "IPM.Note.SMIME.MultipartSigned":a.setIconClass("icon_smime_sign");c.set("message_class","IPM.Note");break;case "IPM.Note.SMIME.SignedEncrypt":a.setIconClass("icon_smime_sign"),c.set("message_class","IPM.Note.SMIME")}}b.saveRecord()},onCertificateCallback:function(a){a.status?Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["plugin.smime.dialog.passphrasewindow"],
this,{manager:Ext.WindowMgr}):container.getNotifier().notify("info.saved",_("S/MIME Message"),a.message)},bidSharedComponent:function(a){var b=-1;switch(a){case Zarafa.core.data.SharedComponentType["plugin.smime.dialog.passphrasewindow"]:b=1;break;case Zarafa.core.data.SharedComponentType["plugin.smime.dialog.changepassphrasecontentpanel"]:b=1}return b},getSharedComponent:function(a){switch(a){case Zarafa.core.data.SharedComponentType["plugin.smime.dialog.passphrasewindow"]:var b=Zarafa.plugins.smime.dialogs.PassphraseContentPanel;
break;case Zarafa.core.data.SharedComponentType["plugin.smime.dialog.changepassphrasecontentpanel"]:b=Zarafa.plugins.smime.dialogs.ChangePassphraseContentPanel}return b},showDefaultColumn:function(){return{header:'<p class="icon_smime_settings">&nbsp;<span class="title">&nbsp'+_("S/MIME Message")+"</span></p>",headerCls:"zarafa-icon-column",dataIndex:"message_class",width:24,sortable:!1,renderer:function(a,b,c){a=c.get("message_class");"IPM.Note.SMIME"==a||"IPM.Note.SMIME.SignedEncrypt"==a?b.css=
"icon_smime_encrypt":"IPM.Note.SMIME.MultipartSigned"==a&&(b.css="icon_smime_sign");return""},fixed:!0,tooltip:_("S/MIME Message")}},showMessageClass:function(a,b){a=b.get("message_class");b="";"IPM.Note.SMIME"==a||"IPM.Note.SMIME.SignedEncrypt"==a?b="icon_smime_encrypt":"IPM.Note.SMIME.MultipartSigned"==a&&(b="icon_smime_sign");return String.format('<td style="width: 24px"><div class="grid_compact {0}" style="height: 24px; width: 24px;">{1}</div></td>',b,"")},getRespectiveDialog:function(a){return(a.ownerCt instanceof
Zarafa.core.ui.Toolbar?a.ownerCt:a.parentMenu.ownerCt.ownerCt).dialog}});Zarafa.core.data.RecordFactory.addFieldToMessageClass("IPM.Note",[{name:"smime",defaultValue:""}]);
Zarafa.onReady(function(){Zarafa.plugins.smime.SMIME_STATUS_GOOD=0;Zarafa.plugins.smime.SMIME_STATUS_PARTIAL=2;Zarafa.plugins.smime.SMIME_STATUS_FATAL=2;Zarafa.plugins.smime.SMIME_DECRYPT_SUCCESS=6;Zarafa.plugins.smime.SMIME_STATUS_INFO=3;Zarafa.plugins.smime.CHANGE_CERTIFICATE_SUCCESS=1;Zarafa.plugins.smime.CHANGE_CERTIFICATE_ERROR=2;Zarafa.plugins.smime.CHANGE_CERTIFICATE_WRONG=3;container.registerPlugin(new Zarafa.core.PluginMetaData({name:"smime",displayName:_("S/MIME Plugin"),pluginConstructor:Zarafa.plugins.smime.SmimePlugin}))});
Ext.namespace("Zarafa.plugins.smime");
Zarafa.plugins.smime.SmimeText=function(){return{createMessage:function(a){return _("grommunio Web can verify digital signatures of emails. A successful verification reassures you that the message has not been tampered with and validates the identity of the sender.")+"<br><br>"+_("You are seeing this message because the verification of the digital signature")+"<b>"+_(" has failed")+"</b>"+_(" for this message.")+"<br><br><b>"+_("What caused this issue?")+"</b><br><br>"+a+"<br><br><b>"+_("What should I do?")+
"</b><br><br>"+_("You can continue to work. However, you should keep in mind that the identity and the authenticity of the message content could not be verified.")+"<br><br>"+_("You can contact your helpdesk or system administrator if you are not sure what to do next.")},getPopupText:function(a){switch(a){case 0:return _("grommunio Web can verify digital signatures of emails. A successful verification reassures you ")+_("that the message has not been tampered with and validates the identity of the sender.")+
"<br><br>"+_("The verification of the digital signature was successful for this email message.");case 1:return Zarafa.plugins.smime.SmimeText.createMessage(_("grommunio Web could not find a public certificate for the recipient."));case 2:return Zarafa.plugins.smime.SmimeText.createMessage(_("The identity of the sender and authenticity of the message content have been verified, but the certificate used to sign the message expired on [d-m-Y]."));case 3:return Zarafa.plugins.smime.SmimeText.createMessage(_("The digital signature could not be verified for unknown reasons."));
case 4:return Zarafa.plugins.smime.SmimeText.createMessage(_("The digital certificate used to sign this message has been revoked (i.e. the sender has marked it as compromised)"));case 5:return Zarafa.plugins.smime.SmimeText.createMessage(_("The verification service of the certificate authority that signed the sender's certificate is not available. The validity of the certificate could not be verified."));case 9:return Zarafa.plugins.smime.SmimeText.createMessage(_("The revocation status of the digital certificate used to sign this email is unknown (Server is unavailable or certificate does not support OCSP). The validity of the certificate could not be verified."));
case 10:return Zarafa.plugins.smime.SmimeText.createMessage(_("The revocation status of the digital certificate used to sign this email is disabled (OCSP). The validity of the certificate could not be verified."));case 11:return Zarafa.plugins.smime.SmimeText.createMessage(_("The certificate verification server (OCSP) is temporarily offline."));case 13:return Zarafa.plugins.smime.SmimeText.createMessage(_("Sender is removed from the server."))}},getMessageInfo:function(a){switch(a){case 0:return _("Signature verified successfully");
case 1:return _("Could not verify signature, missing public certificate");case 2:return _("Signature verification successful, but certificate is expired");case 3:return _("Signature could not be verified");case 4:return _("Certificate has been revoked");case 5:return _("Verification with Certificate Authority failed");case 6:return _("Message decrypted succesfully");case 7:return _("Message decryption failed");case 8:return _("Please")+"<b> "+_("click here")+" </b> "+_("to unlock your certificate");
case 9:return _("Cannot determine revocation status of certificate");case 10:return _("Signature verified (OCSP disabled)");case 11:return _("Cannot determine revocation status of certificate");case 12:return _("Unable to decrypt this message. Certificate does not match");case 13:return _("Verification failed. User is removed from the server.")}},getStatusMessageClass:function(a){switch(a){case 0:return"smime-info-good";case 1:return"smime-info-partial";case 2:return"smime-info-fatal";case 3:return"smime-info-info"}},
getPopupStatus:function(a){switch(a){case 0:return"";case 1:return"warning";case 2:return"error"}}}}();//# sourceMappingURL=smime.js.map
