Date parsing fails: "Could not find your special character: "@""

60 views
Skip to first unread message

Alex C.

unread,
Jan 18, 2017, 6:24:12 AM1/18/17
to GmailDelaySend
Hello!

I just installed GMail Delay Send and it seems that it's not correctly parsing the date/time string.
I generated a mail with the subject "Test delay send" and the contents is:
@now
just a test

Regardles of what date I input (and I've checked it with the Parse Date function), I get an error message stating:
Sorry! There was an error parsing your message with subject: "Test delay send".
The reason for this error was: "Could not find your special character: "@" in FIRST line of email body".
A new label was applied to this message:GmailDelaySend/Errors.
Gmail Delay Send will ignore this message until you fix the problem and remove that label.



I also enabled debugging (whole log below) and it turns out that the regexp pattern does not match. Relevant lines:
Wed Jan 18 02:50:17 PST 2017 INFO: Parsing date and body from email with regex:/^\s*@([^<]*)(<[\s\S]*)/
Wed Jan 18 02:50:17 PST 2017 INFO: Empty Matches

Now, I am not a regexp guru, but to me this sounded like looking for a pattern starting with zero or more white spaces, followed by "@", zero or more characters (anything but "<") plus a second string starting at < and continuing with any char. This seems weird, as it's not mandatory to have the < anywhere in a mail message. However, if I format the first line to be:
@now <
just a test
then the mail gets sent as expected and the matching finds the two substrings:
Wed Jan 18 03:01:37 PST 2017 INFO: Parsing date and body from email with regex:/^\s*@([^<]*)(<[\s\S]*)/
Wed Jan 18 03:01:37 PST 2017 INFO: Match[0] substring:@now <
just a test
--
Alex
Wed Jan 18 03:01:37 PST 2017 INFO: Match[1] substring:now
Wed Jan 18 03:01:37 PST 2017 INFO: Match[2] substring:<
just a test
--
Alex
Wed Jan 18 03:01:37 PST 2017 INFO: Returning date_string: now
Wed Jan 18 03:01:37 PST 2017 INFO: Date String: now Timestamp on message: Wed Jan 18 2017 12:01
Wed Jan 18 03:01:37 PST 2017 INFO: Date to send: Wed Jan 18 2017 03:01


The problem is then, however, that my mail starts with this pesky less-than symbol:
<
just a test.

So: is there something I am really not understanding about the way GMail Delay Send works, or is the regexp broken? Most importantly: how to fix it, without having each mail starting with "<"?

Thanks,

Alex

Full debug log of a failed run:
Wed Jan 18 02:50:17 PST 2017 INFO: Starting main()
Wed Jan 18 02:50:17 PST 2017 INFO: User preferences object empty.. reloading..
Wed Jan 18 02:50:17 PST 2017 INFO: Loading default property for key:bcc value: false
Wed Jan 18 02:50:17 PST 2017 INFO: -- Prefs --
Wed Jan 18 02:50:17 PST 2017 INFO: Triggers: false
Wed Jan 18 02:50:17 PST 2017 INFO: Email Receipts: true
Wed Jan 18 02:50:17 PST 2017 INFO: Error Notifications: true
Wed Jan 18 02:50:17 PST 2017 INFO: Debugging: true
Wed Jan 18 02:50:17 PST 2017 INFO: Top level Name: GmailDelaySend
Wed Jan 18 02:50:17 PST 2017 INFO: Label Required: true
Wed Jan 18 02:50:17 PST 2017 INFO: Error Label Name: GmailDelaySend/Errors
Wed Jan 18 02:50:17 PST 2017 INFO: To Send Label Name: GmailDelaySend/ToSend
Wed Jan 18 02:50:17 PST 2017 INFO: Trigger Minutes: 10
Wed Jan 18 02:50:17 PST 2017 INFO: Delim: @
Wed Jan 18 02:50:17 PST 2017 INFO: TimeZone: Europe/Berlin
Wed Jan 18 02:50:17 PST 2017 INFO: getHTMLRegex: /^([\s\S]*?>)([^<]+)(<[\s\S]*)/
Wed Jan 18 02:50:17 PST 2017 INFO: getTextRegex: /^\s*@([^<]*)(<[\s\S]*)/
Wed Jan 18 02:50:17 PST 2017 INFO: ------------
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache hit
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache hit
Wed Jan 18 02:50:17 PST 2017 INFO: Searching for emails with this string: " label:GmailDelaySend/ToSend -label:GmailDelaySend/Errors "
Wed Jan 18 02:50:17 PST 2017 INFO: Found 1 threads to process
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: User timezone:Europe/Berlin
Wed Jan 18 02:50:17 PST 2017 INFO: Converted:Wed Jan 18 2017 02:50:02 GMT-0800 (PST) to user time:Wed Jan 18 2017 11:50:02 GMT-0800 (PST)
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Is HTML email:false
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Parsing date and body from email with regex:/^\s*@([^<]*)(<[\s\S]*)/
Wed Jan 18 02:50:17 PST 2017 INFO: Empty Matches
Wed Jan 18 02:50:17 PST 2017 INFO: Returning date_string: null
Wed Jan 18 02:50:17 PST 2017 INFO: The message was malformed in some way. Found delimeter:false. Successful date parse: false
Wed Jan 18 02:50:17 PST 2017 INFO: Processing message as error because user requires a label
Wed Jan 18 02:50:17 PST 2017 INFO: Succesfully found label: GmailDelaySend/Errors
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Service cache miss
Wed Jan 18 02:50:17 PST 2017 INFO: Successfully added label (GmailDelaySend/Errors) to message with subject: Test delay send
Wed Jan 18 02:50:17 PST 2017 INFO: Removing label
Wed Jan 18 02:50:18 PST 2017 INFO: Service cache miss

Robert

unread,
Jan 19, 2017, 12:29:05 AM1/19/17
to gmailde...@googlegroups.com
Alex, I'm not going to be much help fixing what you are doing, but I have had no problem using !@! followed by the date, like !@!2017/01/17 1:20 AM.  I haven't tried"now" because if I wanted to send it now I would send it now.
-rrp


Alex C. wrote on 1/18/2017 5:24 AM:0
--
You received this message because you are subscribed to the Google Groups "GmailDelaySend" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysen...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blair Kutzman

unread,
Jan 19, 2017, 12:37:06 PM1/19/17
to gmailde...@googlegroups.com
Hello Alex,

Thanks for the excellent logs and help debugging.

Just to explain the '<' stuff very quickly. When the script accesses the draft email, if the email is HTML it also sees that. So all that is in an attempt to use a regex and account for the HTML leading trailing chars.

Could you do the same test, but write a plain text email?

Thanks,
-Blair

--
You received this message because you are subscribed to the Google Groups "GmailDelaySend" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysend+unsubscribe@googlegroups.com.

Blair Kutzman

unread,
Jan 19, 2017, 12:37:59 PM1/19/17
to gmailde...@googlegroups.com
On Wed, Jan 18, 2017 at 9:28 PM, Robert <robertrp...@gmail.com> wrote:
Alex, I'm not going to be much help fixing what you are doing, but I have had no problem using !@! followed by the date, like !@!2017/01/17 1:20 AM.
  I haven't tried"now" because if I wanted to send it now I would send it now.

​:-) Right, the 'now' option is only for debugging.

-Blair​

 
To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysend+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "GmailDelaySend" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysend+unsubscribe@googlegroups.com.

Alex C.

unread,
Jan 19, 2017, 1:05:09 PM1/19/17
to GmailDelaySend


On Thursday, January 19, 2017 at 6:37:06 PM UTC+1, Blair Kutzman wrote:
Hello Alex,

Thanks for the excellent logs and help debugging.

Just to explain the '<' stuff very quickly. When the script accesses the draft email, if the email is HTML it also sees that. So all that is in an attempt to use a regex and account for the HTML leading trailing chars.

Could you do the same test, but write a plain text email?

Blair, 

thank you for explaining the role of < in the regexp. I am somewhat lost: what I wrote was a PLAINTEXT mail. See screenshot:


Also, the logs suggest me that the regexp used is the "plain text one", not the HTML one:

(...)

Thu Jan 19 09:58:46 PST 2017 INFO: getHTMLRegex: /^([\s\S]*?>)([^<]+)(<[\s\S]*)/
Thu Jan 19 09:58:46 PST 2017 INFO: getTextRegex: /^\s*@([^<]*)(<[\s\S]*)/
(...)
Thu Jan 19 09:58:47 PST 2017 INFO: Parsing date and body from email with regex:/^\s*@([^<]*)(<[\s\S]*)/
Thu Jan 19 09:58:47 PST 2017 INFO: Empty Matches
(...)

Could it be that the (<[\s\S] bit is a copy/paste error from the HTML regex?

Thanks, 

Alex

P.S. Yes, I RTFM and that's why I was using "@now" :)

 

Thanks,
-Blair

To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysen...@googlegroups.com.

Blair Kutzman

unread,
Jan 20, 2017, 12:40:05 AM1/20/17
to gmailde...@googlegroups.com
Ah, sorry I missed that the first time through Alex.

You're copy-paste guess was a good one, but I could have sworn that I had tested this before, so I wrote up a little test.

Creating a new google script which looks like:

function printDraftEmail() {
  Logger.log("Body of email: " + GmailApp.getDraftMessages()[0].getBody());
}

Then composing a text email which contains:
The first line
The second line

Gave me back:
The first line
The second line

Without any HTML, which is consistent with what you had seen. But I could have sworn that there used to be some HTML chars in there (yes, I know, it would be un-expected when the email is a text email).

I poked around some of the old issues for Google Apps Script and found this one: 597.

This reminded me of what I used to see. "<br />" line breaks in a plain text email. Which explains looking for the < in the plain text parsing.

In looking through the GmailApps API, there is a new function getPlainBody() which could work for both HTML and plain text messages.

Honestly it will take me a while to get to this change, but I will eventually. If you'd be willing to take a shot (I assume from the great job that you've done debugging you have some experience) I'd love to review.

It seem unclear from that bug if you could still get some HTML chars in a call to getBody if certain conditions are met. The safe choice would be probably to strip out all the HTML parsing and use getPlainBody() for both the HTML and plain text case. In fact, maybe the distinction between the two could be totally avoided. Anyway, if you do have time to take a look lemme know, otherwise I would suggest either switching to HTML emails w/ the script, or make the small regex change in a local copy and let me know if you run into any issues.

Thanks,
-Blair

To unsubscribe from this group and stop receiving emails from it, send an email to gmaildelaysend+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages