2

I am putting together an Automator workflow that will allow me to bind a hotkey to a Smart Mailbox listing and effectively automate the task of clicking "Unsubscribe" in emails which have that text string.

So far, I've been marginally successful if the actual URL has the word "unsubscribe" in it. What I would like to do, instead, is find where the word Unsubscribe appears and instead grab only those URLs. So in HTML terms, imagine I am finding a link by its text and then acting on the href

When I use content I get only the contents of the email but when I use source I get links. Basically I need a way to map the content to the source.

I hope that makes sense. This is what I have so far:

on run {input, parameters}
set theSource to {}
tell application "Mail"
    repeat with aMessage in input
        -- source or content
        set end of theSource to aMessage's source & return
    end repeat
end tell

return theSource as text
end run
  • Some of those will be mailto links rather than href – markhunte Dec 22 '14 at 19:01
  • True. I'm fine with those being captured as well. Once I have the links returning correctly, I figure I can determine what to do. i.e. Send an email or Trigger a browser open. – webkenny Dec 22 '14 at 19:02
  • Have you found a solution to this? I'm looking for something similar. – james_fuller Apr 29 '15 at 17:59
  • Sadly not yet. I put it on hold for now but I'm still interested in it. – webkenny Apr 29 '15 at 18:25
1

Automatically execute html in an email.

I'm not familiar with Smart Mailbox and what language it uses but below is a VBA script for Outlook that searches for the text "Click" which is a href to a URL, extracts the URL and executes it in Internet Explorer as a weblink.

The code is very messy with very little documentation but it uses the Split Array functionality of VBA to break out the lines of the email message and then extract the correct string after double quotes ""(Chr(34)) using array positioning ie. array urltag(1) - first element in array urltag.

Hope this helps someone.

LaunchURL(itm As MailItem)

Dim bodyString As String
Dim bodyStringSplitLine
Dim bodyStringSplitWord
Dim targetline
Dim urltag
Dim splitLine
Dim splitWord
Dim intCount As Integer
Dim Fail As Integer
Dim Beforecurrent As Integer
Dim Aftercurrent As Integer
Dim Found As Integer


Fail = 0
Found = 0

bodyString = itm.HTMLBody ' Mailitem.body vs Mailitem.HTMLBody  - oMailitem.body
bodyStringSplitLine = Split(bodyString, vbCrLf) 'vbCrLf has no meaning in HTML?

For Each splitLine In bodyStringSplitLine
    bodyStringSplitWord = Split(splitLine, " ")


    For intCount = LBound(bodyStringSplitWord) To UBound(bodyStringSplitWord)
    'For Each splitWord In bodyStringSplitWord ie find out how many iterations to do.

    If intCount > 2 Then
    Beforecurrent = intCount - 1
    Aftercurrent = intCount + 2
    Else
    Beforecurrent = 1
    End If

        If bodyStringSplitWord(intCount) = "click" Then

            targetline = bodyStringSplitWord(Aftercurrent)
            urltag = Split(targetline, Chr(34))
           'i = MsgBox(urltag(1), vbOKOny) test box remove apostrophe to uncomment

            Shell ("C:\Program Files\Internet Explorer\IEXPLORE.EXE" & " " & urltag(1))
           'Shell ("cmd" & " " & "/k" & " " & "echo" & " " & bodyStringSplitWord(Aftercurrent) & " " & Fail & " " & Beforecurrent)   test box remove apostrophe to uncomment

        Found = 1

        Exit Sub
        Else:

        Fail = Fail + 1

        'Shell ("cmd" & " " & "/c" & " " & "echo boo hoo") Test box remove apostrophe to uncomment

        End If
    Next

Next

Set itm = Nothing

End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .