Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13327/src/gui

Modified Files:
        wxComposeView.cpp 
Log Message:
fixed typo in text/binary detection code

Index: wxComposeView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxComposeView.cpp,v
retrieving revision 1.411
retrieving revision 1.412
diff -b -u -2 -r1.411 -r1.412
--- wxComposeView.cpp   26 Jun 2006 23:24:15 -0000      1.411
+++ wxComposeView.cpp   28 Jun 2006 15:30:19 -0000      1.412
@@ -210,6 +210,45 @@
    if ( (fileType == NULL) || !fileType->GetMimeType(&strMimeType) )
    {
-      // can't find MIME type from file extension, set some default one
-      strMimeType = _T("APPLICATION/OCTET-STREAM");
+      // can't find MIME type from file extension, set some default one: use
+      // TEXT/PLAIN for text files and APPLICATION/OCTET-STREAM for binary ones
+
+      bool isBinary = true;
+      if ( wxFile::Access(filename, wxFile::read) )
+      {
+         wxFile file(filename);
+
+         // to check whether the file is text, just read its first 256 bytes
+         // and check if there are any non-alnum characters among them and,
+         // also, if there are any new lines
+         char buf[256];
+         ssize_t len = file.Read(buf, WXSIZEOF(buf));
+         if ( len != -1 )
+         {
+            bool eol = false,
+                 ctrl = false;
+            for ( ssize_t n = 0; n < len && !ctrl; n++ )
+            {
+               const char ch = buf[n];
+               switch ( ch )
+               {
+                  case '\r':
+                  case '\n':
+                     eol = true;
+                     break;
+
+                  case '\t':
+                     break;
+
+                  default:
+                     if ( ch < ' ' || ch == 0x7f )
+                        ctrl = true;
+               }
+            }
+
+            isBinary = !ctrl && eol;
+         }
+      }
+
+      strMimeType = isBinary ? _T("APPLICATION/OCTET-STREAM") : 
_T("TEXT/PLAIN");
    }
 


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to