home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / thunderbird / chrome / mail.jar / content / messenger-smime / msgHdrViewSMIMEOverlay.js < prev    next >
Encoding:
Text File  |  2003-06-05  |  4.8 KB  |  187 lines

  1.  
  2. var gSignedUINode = null;
  3. var gEncryptedUINode = null;
  4. var gSMIMEContainer = null;
  5. var gStatusBar = null;
  6.  
  7. var gEncryptedURIService = null;
  8. var gMyLastEncryptedURI = null;
  9.  
  10. // manipulates some globals from msgReadSMIMEOverlay.js
  11.  
  12. const nsICMSMessageErrors = Components.interfaces.nsICMSMessageErrors;
  13.  
  14. var smimeHeaderSink = 
  15.   maxWantedNesting: function()
  16.   {
  17.     return 1;
  18.   },
  19.  
  20.   signedStatus: function(aNestingLevel, aSignatureStatus, aSignerCert)
  21.   {
  22.     if (aNestingLevel > 1) {
  23.       // we are not interested
  24.       return;
  25.     }
  26.  
  27.     gSignatureStatus = aSignatureStatus;
  28.     gSignerCert = aSignerCert;
  29.  
  30.     gSMIMEContainer.collapsed = false;
  31.     gSignedUINode.collapsed = false;
  32.   
  33.     switch (aSignatureStatus) {
  34.       case nsICMSMessageErrors.SUCCESS:
  35.         gSignedUINode.setAttribute("signed", "ok");
  36.         gStatusBar.setAttribute("signed", "ok");
  37.         break;
  38.  
  39.       case nsICMSMessageErrors.VERIFY_NOT_YET_ATTEMPTED:
  40.         gSignedUINode.setAttribute("signed", "unknown");
  41.         gStatusBar.setAttribute("signed", "unknown");
  42.         break;
  43.  
  44.       case nsICMSMessageErrors.VERIFY_CERT_WITHOUT_ADDRESS:
  45.       case nsICMSMessageErrors.VERIFY_HEADER_MISMATCH:
  46.         gSignedUINode.setAttribute("signed", "mismatch");
  47.         gStatusBar.setAttribute("signed", "mismatch");
  48.         break;
  49.  
  50.       default:
  51.         gSignedUINode.setAttribute("signed", "notok");
  52.         gStatusBar.setAttribute("signed", "notok");
  53.         break;
  54.     }
  55.   },
  56.  
  57.   encryptionStatus: function(aNestingLevel, aEncryptionStatus, aRecipientCert)
  58.   {
  59.     if (aNestingLevel > 1) {
  60.       // we are not interested
  61.       return;
  62.     }
  63.  
  64.     gEncryptionStatus = aEncryptionStatus;
  65.     gEncryptionCert = aRecipientCert;
  66.  
  67.     gSMIMEContainer.collapsed = false; 
  68.     gEncryptedUINode.collapsed = false;
  69.  
  70.     if (nsICMSMessageErrors.SUCCESS == aEncryptionStatus)
  71.     {
  72.       gEncryptedUINode.setAttribute("encrypted", "ok");
  73.       gStatusBar.setAttribute("encrypted", "ok");
  74.     }
  75.     else
  76.     {
  77.       gEncryptedUINode.setAttribute("encrypted", "notok");
  78.       gStatusBar.setAttribute("encrypted", "notok");
  79.     }
  80.     
  81.     if (gEncryptedURIService)
  82.     {
  83.       gMyLastEncryptedURI = GetLoadedMessage();
  84.       gEncryptedURIService.rememberEncrypted(gMyLastEncryptedURI);
  85.     }
  86.   },
  87.  
  88.   QueryInterface : function(iid)
  89.   {
  90.     if (iid.equals(Components.interfaces.nsIMsgSMIMEHeaderSink) || iid.equals(Components.interfaces.nsISupports))
  91.       return this;
  92.     throw Components.results.NS_NOINTERFACE;
  93.   }
  94. };
  95.  
  96. function forgetEncryptedURI()
  97. {
  98.   if (gMyLastEncryptedURI && gEncryptedURIService)
  99.   {
  100.     gEncryptedURIService.forgetEncrypted(gMyLastEncryptedURI);
  101.     gMyLastEncryptedURI = null;
  102.   }
  103. }
  104.  
  105. function onSMIMEStartHeaders()
  106. {
  107.   gEncryptionStatus = -1;
  108.   gSignatureStatus = -1;
  109.   
  110.   gSignerCert = null;
  111.   gEncryptionCert = null;
  112.   
  113.   gSMIMEContainer.collapsed = true;
  114.  
  115.   gSignedUINode.collapsed = true;
  116.   gSignedUINode.removeAttribute("signed");
  117.   gStatusBar.removeAttribute("signed");
  118.  
  119.   gEncryptedUINode.collapsed = true;
  120.   gEncryptedUINode.removeAttribute("encrypted");
  121.   gStatusBar.removeAttribute("encrypted");
  122.  
  123.   forgetEncryptedURI();
  124. }
  125.  
  126. function onSMIMEEndHeaders()
  127. {}
  128.  
  129. function msgHdrViewSMIMEOnLoad(event)
  130. {
  131.   // we want to register our security header sink as an opaque nsISupports
  132.   // on the msgHdrSink used by mail.....
  133.   msgWindow.msgHeaderSink.securityInfo = smimeHeaderSink;
  134.  
  135.   gSignedUINode = document.getElementById('signedHdrIcon');
  136.   gEncryptedUINode = document.getElementById('encryptedHdrIcon');
  137.   gSMIMEContainer = document.getElementById('smimeBox');
  138.   gStatusBar = document.getElementById('status-bar');
  139.  
  140.   // add ourself to the list of message display listeners so we get notified when we are about to display a
  141.   // message.
  142.   var listener = {};
  143.   listener.onStartHeaders = onSMIMEStartHeaders;
  144.   listener.onEndHeaders = onSMIMEEndHeaders;
  145.   gMessageListeners.push(listener);
  146.  
  147.   gEncryptedURIService = 
  148.     Components.classes["@mozilla.org/messenger-smime/smime-encrypted-uris-service;1"]
  149.     .getService(Components.interfaces.nsIEncryptedSMIMEURIsService);
  150. }
  151.  
  152. function msgHdrViewSMIMEOnUnload(event)
  153. {
  154.   forgetEncryptedURI();
  155. }
  156.  
  157. function msgHdrViewSMIMEOnMessagePaneHide()
  158. {
  159.   gSMIMEContainer.collapsed = true;
  160.   gSignedUINode.collapsed = true;
  161.   gEncryptedUINode.collapsed = true;
  162. }
  163.  
  164. function msgHdrViewSMIMEOnMessagePaneUnhide()
  165. {
  166.   if (gEncryptionStatus != -1 || gSignatureStatus != -1)
  167.   {
  168.     gSMIMEContainer.collapsed = false;
  169.  
  170.     if (gSignatureStatus != -1)
  171.     {
  172.       gSignedUINode.collapsed = false;
  173.     }
  174.  
  175.     if (gEncryptionStatus != -1)
  176.     {
  177.       gEncryptedUINode.collapsed = false;
  178.     }
  179.   }
  180. }
  181.  
  182. addEventListener('messagepane-loaded', msgHdrViewSMIMEOnLoad, true);
  183. addEventListener('messagepane-unloaded', msgHdrViewSMIMEOnUnload, true);
  184. addEventListener('messagepane-hide', msgHdrViewSMIMEOnMessagePaneHide, true);
  185. addEventListener('messagepane-unhide', msgHdrViewSMIMEOnMessagePaneUnhide, true);
  186.