[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/filters/libmsooxml
From:       Inge Wallin <inge () lysator ! liu ! se>
Date:       2010-10-26 4:15:50
Message-ID: 20101026041550.8E11EAC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1189852 by ingwa:

Fix a bug where password protected MSOOXML files were reporting the
wrong error message.

BUG: 247515


 M  +48 -0     MsooXmlImport.cpp  
 M  +2 -0      MsooXmlImport.h  


--- trunk/koffice/filters/libmsooxml/MsooXmlImport.cpp #1189851:1189852
@@ -30,6 +30,7 @@
 #include "MsooXmlContentTypes.h"
 #include "MsooXmlRelationships.h"
 #include "MsooXmlThemesReader.h"
+#include "pole.h"
 
 #include <QColor>
 #include <QFile>
@@ -83,6 +84,14 @@
         errorMessage = i18n("Could not open the requested file %1", m_chain->inputFile());
 //! @todo transmit the error to the GUI...
         kDebug() << errorMessage;
+
+        // If the file can't be opened by the zip, it may be a
+        // password protected file.  In OOXML, this is stored as a
+        // standard OLE file with some special streams.
+        QString  inputFilename = m_chain->inputFile();
+        if (isPasswordProtectedFile(inputFilename))
+            return KoFilter::PasswordProtected;
+        else
         return KoFilter::FileNotFound;
     }
 
@@ -124,6 +133,45 @@
     return status;
 }
 
+bool MsooXmlImport::isPasswordProtectedFile(QString &filename)
+{
+    // Open the file.
+    QFile  file(filename);
+    if (!file.open(QIODevice::ReadOnly)) {
+        //kDebug() << "Cannot open " << filename;
+        return false;
+    }
+
+    // Open the OLE storage.
+    POLE::Storage storage(&file);
+    if (!storage.open()) {
+        //kDebug() << "Cannot open" << filename << "as storage";
+        file.close();
+        return false;
+    }
+
+    //kDebug() << "This seems to be an OLE file";
+
+    // Loop through the streams in the file and if one of them is named
+    // "EncryptionInfo", then we probably have a password protected file.
+    bool result = false;
+    std::list<std::string> entries = storage.entries();
+    std::list<std::string>::iterator it;
+    for (it = entries.begin(); it != entries.end(); ++it) {
+        kDebug() << it->c_str();
+        if (*it == "EncryptionInfo") {
+            result = true;
+            break;
+        }
+    }
+
+    // Clean up after us.
+    storage.close();
+    file.close();
+
+    return result;
+}
+
 KoFilter::ConversionStatus MsooXmlImport::copyFile(const QString& sourceName,
         const QString& destinationName, bool oleFile)
 {
--- trunk/koffice/filters/libmsooxml/MsooXmlImport.h #1189851:1189852
@@ -89,6 +89,8 @@
     virtual KoFilter::ConversionStatus createDocument(KoStore *outputStore,
             KoOdfWriters *writers);
 
+    bool isPasswordProtectedFile(QString &filename);
+
     virtual KoFilter::ConversionStatus parseParts(KoOdfWriters *writers,
             MsooXmlRelationships *relationships, QString& errorMessage) = 0;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic