0
$\begingroup$

I am using the function MailSearch[] to get the titles of all the relevant emails in one of my folders in Gmail. What I am currently doing works, but it takes a few seconds, and those seconds really count for what I am doing. Here is the current code:

alerts = 
  Normal[MailSearch[
     connection["Personal/alerts"], <|
      "From" -> "support@xyz.com"|>][[All, "Subject"]]];
actionTitles = 
 Flatten[DeleteCases[
   StringCases[
    alerts, {"Covered " ~~ __, "Covered " ~~ __, "Shorted " ~~ __, 
     "Bought " ~~ __, "Sold " ~~ __}], {}]]

Which returns a list like the following:

{"Covered GLBS", "Covered HTBX", "Shorted HTBX", "Shorted HTBX", \
"Covered HTBX", "Bought KGKG", "Sold KGKG", "Bought TBLT", "Sold \
TBLT", "Bought KGKG", "Sold KGKG", "Bought TAIT", "Sold TAIT", \
"Bought KBLB", "Sold KBLB", "Bought HMPQ", "Sold HMPQ", "Bought \
KBLB", "Sold KBLB"}

The MailSearch[] part of the code is slightly redundant, as all of the mail in the folder Personal/alerts" has already been filtered to be only from the fictitious support@xyz.com. However, I have found this is a lot faster than just using:

connection["Personal/alerts"][All]

Is there an quicker way that I'm not aware of with which I can just get all the Subject entities from the emails in that particular folder? Thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ Have you checked which part is slow? I would suspect that the call to MailSearch is slow, while the second part most probably is pretty fast, but that depends on how many entries you have in alerts and it is always better to check. It will not help a lot but I think the DeleteCases in the second part is superfluos because the Flatten will remove the empty lists anyway and I think is more efficient in doing so... $\endgroup$ – Albert Retey May 16 at 9:40
  • $\begingroup$ @AlbertRetey - Thanks! I hadn't thought of that. And yes, it's definitely the MailSearch function that is causing the most slowdown - I got it working a lot faster, just by using a much smaller inbox. I think maybe the volume of the entire inbox might slow things down, so using a newer email address seemed to help. Something else that would really help would be some sort of functionality that let me just get the text titles of the emails in a specific folder, and then search those by text. $\endgroup$ – Jmeeks29ig May 16 at 23:59
  • $\begingroup$ Unfortunately I have no experience with the MailSearch function, but from its documentation I don't think you can just get the subjects. It might be possible to directly search the subject lines on the server though, which is - if possible - what I think would be the most efficient way to perform the task. Maybe you can change the question (or create a new one) giving a more detailed scope... $\endgroup$ – Albert Retey May 17 at 16:39
  • $\begingroup$ @AlbertRetey - Thanks, I appreciate it, that's a good idea. I did end up just doing most of the work on the server side, which seems to work a lot faster. $\endgroup$ – Jmeeks29ig May 17 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.