Changeset ad01cd


Ignore:
Timestamp:
Mar 11, 2008, 9:05:32 PM (12 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
a8e510
Parents:
1ba1fe
Message:

rearranged account cleanup, added function to remove leftover directories

Location:
chrome/content/v_identity
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_account.js

    r1ba1fe rad01cd  
    8484        }
    8585    },
    86        
     86   
     87    __cleanupDirectories : function() {
     88        var file = Components.classes["@mozilla.org/file/directory_service;1"]
     89        .getService(Components.interfaces.nsIProperties)
     90            .get("ProfD", Components.interfaces.nsIFile);
     91       
     92        var fileEnumerator = file.directoryEntries
     93        while (fileEnumerator.hasMoreElements()) {
     94            var dir = fileEnumerator.getNext()
     95            dir.QueryInterface(Components.interfaces.nsIFile);
     96            if (dir.path.match(new RegExp("[/\\\\]Mail$","i"))) { // match Windows and Linux/Mac separators
     97                var dirEnumerator = dir.directoryEntries
     98                while (dirEnumerator.hasMoreElements()) {
     99                    var maildir = dirEnumerator.getNext()
     100                    maildir.QueryInterface(Components.interfaces.nsIFile);
     101                    if (maildir.path.match(new RegExp("[/\\\\]virtualIdentity.*$","i"))) {// match Windows and Linux/Mac separators
     102                        // should be empty, VirtualIdentity never uses those directories
     103                        try {maildir.remove(false)} catch(e) { };
     104                        vI_notificationBar.dump(".")
     105                    }
     106                }
     107            }
     108        }
     109        vI_notificationBar.dump("\n")
     110    },
     111   
    87112    cleanupSystem : function() {
    88113        vI_notificationBar.dump("## vI_account: cleanupSystem:\n")
     114        vI_notificationBar.dump("## vI_account: checking for leftover VirtualIdentity accounts ")
    89115        for (var i=0; i < vI_account.AccountManager.accounts.Count(); i++) {
    90116            var account = vI_account.AccountManager.accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
    91             vI_account.removeAccount(account);
    92         }
     117            if (vI_account.__isVIdentityAccount(account)) {
     118                vI_notificationBar.dump(".")
     119                vI_account.__removeAccount(account);
     120            }
     121        }
     122        vI_notificationBar.dump("\n## vI_account: checking for leftover VirtualIdentity directories ")
     123        vI_account.__cleanupDirectories();
     124       
    93125        vI_notificationBar.dump("## vI_account: cleanupSystem done.\n")
    94126    },
    95127   
    96     removeAccount : function(account) {
    97         var key = account.key;
    98         var server = account.incomingServer;
    99         if (!server || server.hostName != "virtualIdentity") {
    100             try {   vI_account.prefroot.getBoolPref("mail.account." + account.key + ".vIdentity");
    101                 account.incomingServer = vI_account.AccountManager.
    102                             createIncomingServer("toRemove","virtualIdentity","pop3");
    103             } catch (e) { return; };
    104         }
     128    __isVIdentityAccount : function(account) {
     129        // check for new (post0.5.0) accounts,
     130        try {   vI_account.prefroot.getBoolPref("mail.account." + account.key + ".vIdentity");
     131            return true;
     132        } catch (e) { };
     133        // check for old (pre 0.5.0) accounts
     134        if (account.incomingServer.hostName == "virtualIdentity") return true;
     135        return false;
     136    },
     137   
     138    __removeAccount : function(account) {
     139        // in new (post 0.5.0) Virtual Identity accounts the Incoming Server of the account
     140        // points to an incoming server of a different account. Cause the internal
     141        // removeAccount function tries to removes the incoming server ether, create
     142        // a real one.
     143        if (!account.incomingServer || account.incomingServer.hostName != "virtualIdentity") {
     144            account.incomingServer = vI_account.AccountManager.
     145                createIncomingServer("toRemove","virtualIdentity","pop3");
     146        }
     147
     148        // remove the rootFolder of the account
    105149        try { account.incomingServer.rootFolder.Delete(); }
    106150        catch (e) { };
     151       
     152        var key = account.key;
    107153        vI_notificationBar.dump("## vI_account: removing account " + key + ".\n")
     154        // remove the account
    108155        vI_account.AccountManager.removeAccount(account);
     156        // remove the additional tagging-pref
    109157        try { vI_account.prefroot.clearUserPref("mail.account." + key + ".vIdentity");  }
    110158        catch (e) { };
     
    113161    removeUsedVIAccount : function() {
    114162        if (vI_account.account) {
    115             vI_account.removeAccount(vI_account.account);
     163            vI_account.__removeAccount(vI_account.account);
    116164            vI_account.account = null;
    117165        }
     
    124172            return;
    125173        }
    126        
    127         vI_account.cleanupSystem();
    128        
    129174        /*
    130175        // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this
  • chrome/content/v_identity/vI_upgrade.js

    r1ba1fe rad01cd  
    4545        if (vI_rdfDatasource.extUpgrade()) vI_upgrade.extUpgrade();
    4646        if (vI_rdfDatasource.rdfUpgradeRequired()) vI_upgrade.rdfUpgrade();
     47        vI_account.cleanupSystem();
    4748        vI_notificationBar.dump("\n\nupgrade finished.\n");
    4849        document.documentElement.getButton('next').setAttribute('disabled','false');
  • chrome/content/v_identity/vI_upgradeOverlay.js

    r1ba1fe rad01cd  
    2525vI_upgradeOverlay = {
    2626    init: function() {
    27         vI_account.cleanupSystem(); // clean leftover accounts
    2827        vI_rdfDatasource.init() // just to be sure that Datasource is available
    2928        if (vI_rdfDatasource.rdfUpgradeRequired() || vI_rdfDatasource.extUpgrade())     
    3029            window.openDialog("chrome://v_identity/content/vI_upgrade.xul",0, // give the Dialog a unique id
    3130                "chrome, dialog, modal, alwaysRaised, resizable=yes").focus();
     31        else vI_account.cleanupSystem(); // always clean leftover accounts and directories
    3232
    3333    }
  • chrome/content/v_identity/vI_upgradeOverlay.xul

    r1ba1fe rad01cd  
    3434<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    3535    <script type="application/x-javascript" src="chrome://v_identity/content/vI_upgradeOverlay.js" />
     36    <script type="application/x-javascript" src="chrome://v_identity/content/vI_account.js" />
    3637    <script type="application/x-javascript" src="chrome://v_identity/content/vI_rdfDatasource.js" />
    3738    <!-- following element just stores the Ext-Version, seamonkey has no extensionmanager -->
Note: See TracChangeset for help on using the changeset viewer.