Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird Issue on single message thread. #1

Open
Ionshard opened this issue Aug 20, 2015 · 4 comments
Open

Weird Issue on single message thread. #1

Ionshard opened this issue Aug 20, 2015 · 4 comments

Comments

@Ionshard
Copy link

I attempted to implement the snoozever script and I was getting empty notes titled "To do from inbox - "

Now I throw some logging in.
Given

  /***********************************************
  * ACTION
  ***********************************************/

  // Get snoozed threads
  var threads = GmailApp.search('label:snoozed');


  // Loop of snoozed threads
  for(i in threads){

    // Get last message of threads
    var message = threads[i].getMessages()[threads[i].getMessageCount()-1];

    Logger.log('Message Count ' + threads[i].getMessageCount());
    Logger.log('Last Index ' + (threads[i].getMessageCount()-1));
    Logger.log('Subject ' + message.getSubject());

//    //Forward last message to evernote
//    message.forward(evernoteEmail, {
//      subject: 'Email: '+message.getSubject()+' '+tags+' '+notebook
//    });
//
//    // Mark thread as done
//     GmailApp.moveThreadToArchive(threads[i]);

I get the following logs

[15-08-20 15:27:19:415 EDT] Message Count 2
[15-08-20 15:27:19:416 EDT] Last Index 1
[15-08-20 15:27:19:416 EDT] Subject 

I change the following code (I'm no javascript expert) so I don't know why this worked.

   // Get last message of threads
    var last_index = threads[i].getMessageCount()-1;
    var message = threads[i].getMessages()[last_index];

Which results in finding the correct message

[15-08-20 15:31:06:603 EDT] Message Count 2
[15-08-20 15:31:06:604 EDT] Last Index 1
[15-08-20 15:31:06:605 EDT] Subject Your official start time and important event information for Tough Mudder Pittsburgh

I don't know if others are having this issue but figured I'd let you know. Again that shouldn't have fixed anything but I can revert it and see the exact issue again.

@sandoche
Copy link
Owner

That's quite weird, I am using this script since February and I never had any problems with it.
But thanks for you message that can helps others facing this problem :)

@shannonfenn
Copy link

The answer may lie here:

var last_index = threads[i].getMessageCount()-1;
var len = threads[i].getMessageCount();

Logger.log(threads[i].getMessageCount())
Logger.log(len)
Logger.log(threads[i].getMessageCount() - 1)
Logger.log(last_index)

result:

[16-01-12 12:21:55:798 AEDT] 2.0
[16-01-12 12:21:55:799 AEDT] 1.0
[16-01-12 12:21:55:800 AEDT] 1.0
[16-01-12 12:21:55:800 AEDT] 0.0

This being my first experience in javascript I can hardly diagnose, but there seems to be some problems with the array length being interpreted as the wrong integer value in expressions, but being resolved correctly when storing into a variable. The issue also occurs for a thread of 3 messages where I get a blank email due to an attempt to access a non-existant 4th element.

@Ionshard
Copy link
Author

Let me just rephrase that so I can collect like terms

Logger.log(threads[i].getMessageCount())
//[16-01-12 12:21:55:798 AEDT] 2.0

var len = threads[i].getMessageCount();
Logger.log(len)
//[16-01-12 12:21:55:799 AEDT] 1.0

Logger.log(threads[i].getMessageCount() - 1)
//[16-01-12 12:21:55:800 AEDT] 1.0

var last_index = threads[i].getMessageCount()-1;
Logger.log(last_index)
//[16-01-12 12:21:55:800 AEDT] 0.0

Wow! This is every programmer's worst nightmare. A statement that evaluates to a different value if it's stored in a variable. Maybe this is some kind of rounding issue behind the scenes?

@shannonfenn
Copy link

You're likely correct, the lack of a built in integral type and weird array issues in general are worrying. Nonetheless your original proposed solution has worked for me with single and multi-message threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants