Fixed bug where items in sent folder have "invalid date"

This commit is contained in:
EthanBlackburn 2015-07-31 08:23:03 -07:00
parent 6609fe272c
commit 3e01a10758
5 changed files with 142 additions and 3 deletions

View file

@ -153,7 +153,7 @@ class MessageItem extends React.Component
_renderEvents: =>
events = @_eventComponents()
if events.length > 0 and Utils.looksLikeGmailInvite(@props.message)
if events.length > 0 and not Utils.looksLikeGmailInvite(@props.message)
<div className="events-area">{events}</div>
else
<div></div>

View file

@ -19,6 +19,7 @@ describe "EventStore", ->
it "initializes the cache from the DB", ->
spyOn(DatabaseStore, "findAll").andCallFake -> Promise.resolve([])
advanceClock(30)
EventStore.constructor()
advanceClock(30)
expect(Object.keys(EventStore._eventCache).length).toBe 0

View file

@ -348,6 +348,141 @@ describe "isEqual", ->
other = {a: 1}
ok(!Utils.isEqual(new Foo, other))
describe "looksLikeGmailInvite", ->
it "should return false for an exchange invite", ->
message = {
body: """<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div style="">
<table cellspacing="0" cellpadding="8" border="0" summary="" style="width:100%;font-family:Arial,Sans-serif;border:1px Solid #ccc;border-width:1px 2px 2px 1px;background-color:#fff;" itemscope="" itemtype="http://schema.org/Event">
<tbody>
<tr>
<td>
<meta itemprop="eventStatus" content="http://schema.org/EventScheduled">
<div style="padding:2px"><span itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Google Calendar">
</span>
<meta itemprop="eventId/googleCalendar" content="p068hq4mrslsbnddg0a8kdfg2s">
<div style="float:right;font-weight:bold;font-size:13px"><a href="https://www.google.com/calendar/event?action=VIEW&amp;eid=cDA2OGhxNG1yc2xzY…hYzQwYjFhNzEwZWUyZjkxNjI3ZTZlMzk3Yjk4NzQ4YWVhNjA4Nzg&amp;ctz=UTC&amp;hl=en" style="color:#20c;white-space:nowrap" itemprop="url">more
details »</a><br>
</div>
<h3 style="padding:0 0 6px 0;margin:0;font-family:Arial,Sans-serif;font-size:16px;font-weight:bold;color:#222">
<span itemprop="name">(No Subject)</span></h3>
<table cellpadding="0" cellspacing="0" border="0" summary="Event details">
<tbody>
<tr>
<td style="padding:0 1em 10px 0;font-family:Arial,Sans-serif;font-size:13px;color:#888;white-space:nowrap" valign="top">
<div><i style="font-style:normal">When</i></div>
</td>
<td style="padding-bottom:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222" valign="top">
<time itemprop="startDate" datetime="20150730T220000Z"></time><time itemprop="endDate" datetime="20150730T230000Z"></time>Thu Jul 30, 2015 10pm &#8211; 11pm
<span style="color:#888">GMT (no daylight saving)</span></td>
</tr>
<tr>
<td style="padding:0 1em 10px 0;font-family:Arial,Sans-serif;font-size:13px;color:#888;white-space:nowrap" valign="top">
<div><i style="font-style:normal">Calendar</i></div>
</td>
<td style="padding-bottom:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222" valign="top">
ethan@nylas.com</td>
</tr>
<tr>
<td style="padding:0 1em 10px 0;font-family:Arial,Sans-serif;font-size:13px;color:#888;white-space:nowrap" valign="top">
<div><i style="font-style:normal">Who</i></div>
</td>
<td style="padding-bottom:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222" valign="top">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding-right:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222">
<span style="font-family:Courier New,monospace">&#8226;</span></td>
<td style="padding-right:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222">
<div>
<div style="margin:0 0 0.3em 0"><span itemprop="attendee" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name">Ethan Blackburn</span>
<meta itemprop="email" content="eblackb1@slu.edu">
</span><span style="font-size:11px;color:#888"> - organizer</span></div>
</div>
</td>
</tr>
<tr>
<td style="padding-right:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222">
<span style="font-family:Courier New,monospace">&#8226;</span></td>
<td style="padding-right:10px;font-family:Arial,Sans-serif;font-size:13px;color:#222">
<div>
<div style="margin:0 0 0.3em 0"><span itemprop="attendee" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name">ethan@nylas.com</span>
<meta itemprop="email" content="ethan@nylas.com">
</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<p style="color:#222;font-size:13px;margin:0"><span style="color:#888">Going? </span>
<wbr><strong><span itemprop="action" itemscope="" itemtype="http://schema.org/RsvpAction">
<meta itemprop="attendance" content="http://schema.org/RsvpAttendance/Yes">
<span itemprop="handler" itemscope="" itemtype="http://schema.org/HttpActionHandler"><link itemprop="method" href="http://schema.org/HttpRequestMethod/GET"><a href="https://www.google.com/calendar/event?action=RESPOND&amp;eid=cDA2OGhxNG1yc2…hYzQwYjFhNzEwZWUyZjkxNjI3ZTZlMzk3Yjk4NzQ4YWVhNjA4Nzg&amp;ctz=UTC&amp;hl=en" style="color:#20c;white-space:nowrap" itemprop="url">Yes</a></span></span><span style="margin:0 0.4em;font-weight:normal">
- </span><span itemprop="action" itemscope="" itemtype="http://schema.org/RsvpAction">
<meta itemprop="attendance" content="http://schema.org/RsvpAttendance/Maybe">
<span itemprop="handler" itemscope="" itemtype="http://schema.org/HttpActionHandler"><link itemprop="method" href="http://schema.org/HttpRequestMethod/GET"><a href="https://www.google.com/calendar/event?action=RESPOND&amp;eid=cDA2OGhxNG1yc2…hYzQwYjFhNzEwZWUyZjkxNjI3ZTZlMzk3Yjk4NzQ4YWVhNjA4Nzg&amp;ctz=UTC&amp;hl=en" style="color:#20c;white-space:nowrap" itemprop="url">Maybe</a></span></span><span style="margin:0 0.4em;font-weight:normal">
- </span><span itemprop="action" itemscope="" itemtype="http://schema.org/RsvpAction">
<meta itemprop="attendance" content="http://schema.org/RsvpAttendance/No">
<span itemprop="handler" itemscope="" itemtype="http://schema.org/HttpActionHandler"><link itemprop="method" href="http://schema.org/HttpRequestMethod/GET"><a href="https://www.google.com/calendar/event?action=RESPOND&amp;eid=cDA2OGhxNG1yc2…hYzQwYjFhNzEwZWUyZjkxNjI3ZTZlMzk3Yjk4NzQ4YWVhNjA4Nzg&amp;ctz=UTC&amp;hl=en" style="color:#20c;white-space:nowrap" itemprop="url">No</a></span></span></strong>
<wbr><a href="https://www.google.com/calendar/event?action=VIEW&amp;eid=cDA2OGhxNG1yc2xzY…hYzQwYjFhNzEwZWUyZjkxNjI3ZTZlMzk3Yjk4NzQ4YWVhNjA4Nzg&amp;ctz=UTC&amp;hl=en" style="color:#20c;white-space:nowrap" itemprop="url">more
options »</a></p>
</td>
</tr>
<tr>
<td style="background-color:#f6f6f6;color:#888;border-top:1px Solid #ccc;font-family:Arial,Sans-serif;font-size:11px">
<p>Invitation from <a href="https://www.google.com/calendar/" target="_blank" style="">
Google Calendar</a></p>
<p>You are receiving this email at the account ethan@nylas.com because you are subscribed for invitations on calendar ethan@nylas.com.</p>
<p>To stop receiving these emails, please log in to https://www.google.com/calendar/ and change your notification settings for this calendar.</p>
<p>Forwarding this invitation could allow any recipient to modify your RSVP response.
<a href="https://support.google.com/calendar/answer/37135#forwarding">Learn More</a>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>"""
}
expect(Utils.looksLikeGmailInvite(message)).toEqual(true)
it "should return true for a gmail invite", ->
message = {
body: """<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Begin forwarded message: <br>
<br>
From: Originator &lt;originator@nylas.com&gt;<br>
Subject: &lt;&gt; Nylas E-mail Call and Webhooks review<br>
Date: Jul 28 2015, at 2:32 pm<br>
To: random@guy.com &lt;random@guy.com&gt;, Someone Else &lt;someone@else.com&gt;
<br>
<br>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
Call to review Pipeline Deals email tool and webhooks support.</div>
</blockquote>
</body>
</html>"""
}
describe "subjectWithPrefix", ->
it "should replace an existing Re:", ->
expect(Utils.subjectWithPrefix("Re: Test Case", "Fwd:")).toEqual("Fwd: Test Case")

View file

@ -67,8 +67,10 @@ Utils =
looksLikeGmailInvite: (message={}) ->
if 'PRODID:-//Google Inc//Google Calendar' in message.body
return true
idx = message.body.search('itemtype="http://schema.org/Event"')
if idx == -1
return false
return true
# Escapes potentially dangerous html characters

View file

@ -48,6 +48,7 @@ class EventStore extends NylasStore
Actions.queueTask(task)
__refreshCache: =>
console.log('here')
new Promise (resolve, reject) =>
DatabaseStore.findAll(Event)
.then (events=[]) =>