title: Applescript that filters the subject line of emails in Inbox
body: <p>I am trying to write a script that does the following job: it goes through all of the emails in the mailbox, finds the ones that have the word "French" in their subject line and then copies all the subject lines of those emails in a text file. Here is what I came up with</p>
  
  <pre><code>tell application "TextEdit"
      make new document
  end tell
  
  tell application "Mail"
      tell the mailbox "Inbox" of account "tigeresque@gmail.com"
          set numm to count of messages
              repeat with kk from 1 to numm
                  set wordsub to subject of the message kk
                  tell application "TextEdit"
                      if "French" is in wordsub then
                          set paragraph kk of front document to wordsub &amp; return
                      end if
                  end tell
              end repeat
      end tell
  end tell
  </code></pre>
  
  <p>Unfortunately, I keep receiving the error </p>
  
  <blockquote>
    <p>"TextEdit got an error: The index of the event is too large to be valid." </p>
  </blockquote>
  
  <p>and I have already spent a couple of hours trying to fix it without much success. Could you please take a look at my code and see what is wrong with it?</p>