[Libreoffice-commits] core.git: 3 commits - sfx2/source shell/source

Stephan Bergmann sbergman at redhat.com
Mon Feb 10 02:25:22 PST 2014


 sfx2/source/dialog/mailmodel.cxx      |   11 +++-
 shell/source/cmdmail/cmdmailsuppl.cxx |   93 ++++++++++++++++++++++++----------
 2 files changed, 76 insertions(+), 28 deletions(-)

New commits:
commit 5c8a3bfc7e42009a7eaa6353cf2f66a14bfdab76
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Feb 10 11:23:09 2014 +0100

    Don't call pclose(NULL)
    
    Change-Id: I6540ec2b900e82745d5e661dfa920f85db6c0ff2

diff --git a/shell/source/cmdmail/cmdmailsuppl.cxx b/shell/source/cmdmail/cmdmailsuppl.cxx
index 7730f05..7f40594 100644
--- a/shell/source/cmdmail/cmdmailsuppl.cxx
+++ b/shell/source/cmdmail/cmdmailsuppl.cxx
@@ -301,7 +301,8 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
     }
 
     OString cmd = aBuffer.makeStringAndClear();
-    if ( 0 != pclose(popen(cmd.getStr(), "w")) )
+    FILE * f = popen(cmd.getStr(), "w");
+    if (f == 0 || pclose(f) != 0)
     {
         throw ::com::sun::star::uno::Exception("No mail client configured",
             static_cast < XSimpleMailClient * > (this) );
commit f669e7907bef8585fd182986c708e2e4aed280aa
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Feb 10 11:20:12 2014 +0100

    Properly encode cmd line for popen
    
    Change-Id: I1f7799920b6732a6cd128143dfa7ce282bad25c6

diff --git a/shell/source/cmdmail/cmdmailsuppl.cxx b/shell/source/cmdmail/cmdmailsuppl.cxx
index 5b1b403..7730f05 100644
--- a/shell/source/cmdmail/cmdmailsuppl.cxx
+++ b/shell/source/cmdmail/cmdmailsuppl.cxx
@@ -109,6 +109,47 @@ Reference< XSimpleMailMessage > SAL_CALL CmdMailSuppl::createSimpleMailMessage(
 // XSimpleMailClient
 //------------------------------------------------
 
+namespace {
+
+void appendShellWord(OStringBuffer & buffer, OUString const & word, bool strict)
+{
+    OString sys;
+    if (!word.convertToString(
+            &sys, osl_getThreadTextEncoding(),
+            (strict
+             ? (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+                | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)
+             : OUSTRING_TO_OSTRING_CVTFLAGS)))
+    {
+        throw css::uno::Exception(
+            ("Could not convert \"" + word + "\" to encoding #"
+             + OUString::number(osl_getThreadTextEncoding())),
+            css::uno::Reference<css::uno::XInterface>());
+    }
+    buffer.append('\'');
+    for (sal_Int32 i = 0; i != sys.getLength(); ++i) {
+        char c = sys[i];
+        switch (c) {
+        case 0:
+            if (strict) {
+                throw css::uno::Exception(
+                    "Could not convert word containing NUL, \"" + word + "\"",
+                    css::uno::Reference<css::uno::XInterface>());
+            }
+            break;
+        case '\'':
+            buffer.append("'\\''");
+            break;
+        default:
+            buffer.append(c);
+            break;
+        }
+    }
+    buffer.append('\'');
+}
+
+}
+
 void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailMessage >& xSimpleMailMessage, sal_Int32 /*aFlag*/ )
     throw (IllegalArgumentException, Exception, RuntimeException)
 {
@@ -135,7 +176,8 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
             static_cast < XSimpleMailClient * > (this));
     }
 
-    OStringBuffer aBuffer("\"" + OUStringToOString(aProgram, osl_getThreadTextEncoding()) + "\" ");
+    OStringBuffer aBuffer;
+    appendShellWord(aBuffer, aProgram, true);
 
     try
     {
@@ -171,12 +213,12 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
                 // make sure we have a system path
                 FileBase::getSystemPathFromFileURL( aMailer, aMailer );
 
-                aBuffer.append("--mailclient " + OUStringToOString( aMailer, osl_getThreadTextEncoding() ) +
-                               " ");
+                aBuffer.append(" --mailclient ");
+                appendShellWord(aBuffer, aMailer, true);
             }
 #ifdef MACOSX
             else
-                aBuffer.append("--mailclient Mail ");
+                aBuffer.append(" --mailclient Mail");
 #endif
         }
 
@@ -196,26 +238,28 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
         rtl::OUString sBody = xMessage->getBody();
         if ( sBody.getLength() > 0 )
         {
-            aBuffer.append("--body \"");
-            aBuffer.append(OUStringToOString(sBody, osl_getThreadTextEncoding()));
-            aBuffer.append("\" ");
+            aBuffer.append(" --body ");
+            appendShellWord(aBuffer, sBody, false);
         }
     }
 
+    // Convert from, to, etc. in a best-effort rather than a strict way to the
+    // system encoding, based on the assumption that the relevant address parts
+    // of those strings are ASCII anyway and any problematic characters are only
+    // in the human-readable, informational-only parts:
+
     // Append originator if set in the message
     if ( !xSimpleMailMessage->getOriginator().isEmpty() )
     {
-        aBuffer.append("--from \"" +
-                        OUStringToOString(xSimpleMailMessage->getOriginator(), osl_getThreadTextEncoding()) +
-                       "\" ");
+        aBuffer.append(" --from ");
+        appendShellWord(aBuffer, xSimpleMailMessage->getOriginator(), false);
     }
 
     // Append receipient if set in the message
     if ( !xSimpleMailMessage->getRecipient().isEmpty() )
     {
-        aBuffer.append("--to \"" +
-                       OUStringToOString(xSimpleMailMessage->getRecipient(), osl_getThreadTextEncoding()) +
-                       "\" ");
+        aBuffer.append(" --to ");
+        appendShellWord(aBuffer, xSimpleMailMessage->getRecipient(), false);
     }
 
     // Append carbon copy receipients set in the message
@@ -223,9 +267,8 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
     sal_Int32 n, nmax = aStringList.getLength();
     for ( n = 0; n < nmax; n++ )
     {
-        aBuffer.append("--cc \"" +
-                       OUStringToOString(aStringList[n], osl_getThreadTextEncoding()) +
-                       "\" ");
+        aBuffer.append(" --cc ");
+        appendShellWord(aBuffer, aStringList[n], false);
     }
 
     // Append blind carbon copy receipients set in the message
@@ -233,17 +276,15 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
     nmax = aStringList.getLength();
     for ( n = 0; n < nmax; n++ )
     {
-        aBuffer.append("--bcc \"" +
-                       OUStringToOString(aStringList[n], osl_getThreadTextEncoding()) +
-                       "\" ");
+        aBuffer.append(" --bcc ");
+        appendShellWord(aBuffer, aStringList[n], false);
     }
 
     // Append subject if set in the message
     if ( !xSimpleMailMessage->getSubject().isEmpty() )
     {
-        aBuffer.append("--subject \"" +
-                       OUStringToOString(xSimpleMailMessage->getSubject(), osl_getThreadTextEncoding()) +
-                       "\" ");
+        aBuffer.append(" --subject ");
+        appendShellWord(aBuffer, xSimpleMailMessage->getSubject(), false);
     }
 
     // Append attachments set in the message
@@ -254,9 +295,8 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
         OUString aSystemPath;
         if ( FileBase::E_None == FileBase::getSystemPathFromFileURL(aStringList[n], aSystemPath) )
         {
-            aBuffer.append("--attach \"" +
-                           OUStringToOString(aSystemPath, osl_getThreadTextEncoding()) +
-                           "\" ");
+            aBuffer.append(" --attach ");
+            appendShellWord(aBuffer, aSystemPath, true);
         }
     }
 
commit 740fe0ce142c521d3a75558dea6535017821e127
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Feb 10 11:18:33 2014 +0100

    Resolves: rhbz#1063170 Don't URI-encode filename in e-mail subject
    
    Change-Id: I7e3f59af5bb7d89c74e2bf199a727b2419714121

diff --git a/sfx2/source/dialog/mailmodel.cxx b/sfx2/source/dialog/mailmodel.cxx
index 8e2110a..0efcebc 100644
--- a/sfx2/source/dialog/mailmodel.cxx
+++ b/sfx2/source/dialog/mailmodel.cxx
@@ -849,8 +849,15 @@ SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css:
                 Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size());
 
                 if ( xSimpleMailMessage->getSubject().isEmpty() ) {
-                    OUString baseName( maAttachedDocuments[0].copy( maAttachedDocuments[0].lastIndexOf( '/' ) + 1 ) );
-                    OUString subject( baseName );
+                    INetURLObject url(
+                        maAttachedDocuments[0], INetURLObject::WAS_ENCODED);
+                    OUString subject(
+                        url.getName(
+                            INetURLObject::LAST_SEGMENT, false,
+                            INetURLObject::DECODE_WITH_CHARSET));
+                    if (subject.isEmpty()) {
+                        subject = maAttachedDocuments[0];
+                    }
                     if ( maAttachedDocuments.size() > 1 )
                         subject += ", ...";
                     xSimpleMailMessage->setSubject( subject );


More information about the Libreoffice-commits mailing list