David Graf has proposed merging 
lp:~zorba-coders/zorba/email-module-dayofweek-fix into lp:zorba/email-module.

Requested reviews:
  Chris Hillery (ceejatec)
  Sorin Marian Nasoi (sorin.marian.nasoi)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/email-module-dayofweek-fix/+merge/108335

Date of emails do sometimes not contain the day of the week.
-- 
https://code.launchpad.net/~zorba-coders/zorba/email-module-dayofweek-fix/+merge/108335
Your team Zorba Coders is subscribed to branch lp:zorba/email-module.
=== modified file 'src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp'
--- src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp	2012-01-24 11:30:35 +0000
+++ src/com/zorba-xquery/www/modules/email/imap.xq.src/imap_function.cpp	2012-06-01 12:49:33 +0000
@@ -178,12 +178,22 @@
   
   std::string lMonths = "JanFebMarAprMayJunJulAugSepOctNovDec";
   size_t lMonthNumber = lMonths.find(lTokens[2]);
-  // if the month was not found, were really in trouble!
+  size_t lTokensShift = 0;
   if (lMonthNumber == std::string::npos) {
-    Item lQName = theModule->getItemFactory()->createQName(SCHEMA_NAMESPACE,
-        "XPTY0004");
-    throw USER_EXCEPTION(lQName, "Error while processing month in date of message");
-  }  
+    // if the month is not there, day of week is possibly missing, 
+    // shift tokens by one and retry
+    lTokensShift = -1;
+    lMonthNumber = lMonths.find(lTokens[2 + lTokensShift]);
+    if (lMonthNumber == std::string::npos) {
+      // now, we are really in trouble, something is wrong
+      Item lQName = theModule->getItemFactory()
+                      ->createQName(SCHEMA_NAMESPACE, "XPTY0004");
+      throw USER_EXCEPTION(
+              lQName, 
+              "Error while processing month in date of email message");
+    }
+  }
+
   lMonthNumber = lMonthNumber/3 + 1;
   // make sure its MM and not just <
   if (lMonthNumber < 10) {
@@ -191,12 +201,15 @@
   }  
   lResult << lMonthNumber << "-";
   
-  if (lTokens[1].size() == 1) {
+  if (lTokens[1 + lTokensShift].size() == 1) {
     lResult << 0;
   }
-  lResult << lTokens[1] << "T";
+  lResult << lTokens[1 + lTokensShift] << "T";
   // now hh:mm:ss
-  lResult << lTokens[4].substr(0,2) << ":" << lTokens[4].substr(3,2) << ":" << lTokens[4].substr(6,2);
+  lResult << lTokens[4 + lTokensShift].substr(0,2) << ":" 
+    << lTokens[4 + lTokensShift].substr(3,2) << ":" 
+    << lTokens[4 + lTokensShift].substr(6,2);
+
 
   return lResult.str();
   

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to