                         
                         # choose the right date
                         if mailParsedObject.headers.date
-                          if mailParsedObject.headers.date.toString() == '[object Array]'
+                          if mailParsedObject.headers.date instanceof Array
                             # if an array pick the first date
                             dateSent = new Date mailParsedObject.headers.date[0]
                           else
+                            # else take the whole thing
                             dateSent = new Date mailParsedObject.headers.date
                         else
                           dateSent = new Date()

                                
                                # when finished
                                if mailsToGo == mailsDone
                                  callback()
                              
                                # TODO a timeout

                          flagged:      "\\Flagged" in messageFlags
                      
                          hasAttachments: if mailParsedObject.attachments then true else false
                        
                        # and now we can create a new mail on database, as a child of this mailbox
                        mailbox.mails.create mail, (err, mail) ->
    
