Opened 2 years ago

Closed 2 years ago

#1487856 closed Bugs (fixed)

Column 'date' cannot be null

Reported by: unicorn Owned by:
Priority: 5 Milestone: 0.6-beta
Component: Database Version: 0.5.1
Severity: normal Keywords:
Cc:

Description

Could you add this patch to the rcube_imap and method add_message_cache? It's solution when incoming spam hasn't valid timestamp.

    	$timestamp = $headers->timestamp;
        	if (!date('Ymd', $timestamp)) {
        		$timestamp = time();
        	}
        	
            $this->db->query(
                "INSERT INTO ".get_table_name('messages').
                " (user_id, del, cache_key, created, idx, uid, subject, ".
                $this->db->quoteIdentifier('from').", ".
                $this->db->quoteIdentifier('to').", ".
                "cc, date, size, headers, structure)".
                " VALUES (?, 0, ?, ".$this->db->now().", ?, ?, ?, ?, ?, ?, ".
                $this->db->fromunixtime($timestamp).", ?, ?, ?)",
                $_SESSION['user_id'],
                $key,
                $index,
                $headers->uid,
                (string)mb_substr($this->db->encode($this->decode_header($headers->subject, true)), 0, 128),
                (string)mb_substr($this->db->encode($this->decode_header($headers->from, true)), 0, 128),
                (string)mb_substr($this->db->encode($this->decode_header($headers->to, true)), 0, 128),
                (string)mb_substr($this->db->encode($this->decode_header($headers->cc, true)), 0, 128),
                (int)$headers->size,
                serialize($this->db->encode(clone $headers)),
                is_object($struct) ? serialize($this->db->encode(clone $struct)) : NULL
			);
        }

Attachments (2)

SPAM____ w.geqian_________2.eml (14.3 KB) - added by unicorn 2 years ago.
This e-mail cause MySQL error.
log.txt (1.3 KB) - added by unicorn 2 years ago.
IMAP + Error log

Download all attachments as: .zip

Change History (11)

comment:1 Changed 2 years ago by unicorn

  • Milestone changed from later to 0.6-beta

comment:2 Changed 2 years ago by unicorn

  • Component changed from Addressbook to IMAP connection

comment:3 follow-up: Changed 2 years ago by alec

Invalid Date header shouldn't be an issue. Could you provide imap_debug log and sample message? Additional info about your environment would be useful.

Changed 2 years ago by unicorn

This e-mail cause MySQL error.

comment:4 in reply to: ↑ 3 Changed 2 years ago by unicorn

Replying to alec:

Invalid Date header shouldn't be an issue. Could you provide imap_debug log and sample message? Additional info about your environment would be useful.

I attached the file with content, which can't be inserted to the MySQL table messages. MySQL return Column 'date' cannot be null, when try insert to the table.

comment:5 Changed 2 years ago by alec

No error in my environment. Roundcube date parsing function converts the date to 2011-04-04. So, we need imap_debug to make sure what your IMAP server returns to the Roundcube. Additional info like PHP version IMAP server version, etc. would be helpful.

comment:6 Changed 2 years ago by alec

You can also check sql_debug to find how exactly looks the query.

Changed 2 years ago by unicorn

IMAP + Error log

comment:7 Changed 2 years ago by alec

Now I see that the problem is with "FROM_UNIXTIME(4110652800)". This function returns NULL for out-of-range values. So, the fix is as follows:

--- rcube_mdb2.old      2011-02-28 17:48:21.000000000 +0100
+++ rcube_mdb2.php      2011-04-06 10:29:01.000000000 +0200
@@ -570,15 +570,7 @@
      */
     function fromunixtime($timestamp)
     {
-        switch($this->db_provider) {
-            case 'mysqli':
-            case 'mysql':
-            case 'sqlite':
-                return sprintf("FROM_UNIXTIME(%d)", $timestamp);
-
-            default:
-                return date("'Y-m-d H:i:s'", $timestamp);
-        }
+        return date("'Y-m-d H:i:s'", $timestamp);
     }

comment:8 Changed 2 years ago by unicorn

It seems fixed.

comment:9 Changed 2 years ago by alec

  • Component changed from IMAP connection to Database
  • Resolution set to fixed
  • Status changed from new to closed

Applied in [6491fbdb].

Note: See TracTickets for help on using tickets.