Script not working as needed

I commented the code not working as wanted.

using terms from application "Mail"
	on perform mail action with messages theMessages
		tell application "Mail"
			repeat with eachMessage in theMessages
				set thisContent to get content of eachMessage
				my commands(thisContent)
			end repeat
		end tell
	end perform mail action with messages
end using terms from

on commands(thisContent)
	set tmpFolderText to "Macintosh Hd:tmp:1.txt"
	
	try
		set fileRef to open for access tmpFolderText with write permission
		set eof fileRef to 0
		write thisContent to fileRef
		close access fileRef
	on error
		try
			close access fileRef
			display dialog "Failed to write to file." giving up after 5 with icon 0
		end try
	end try
	
	--Error here

	do shell script "cat /tmp/1.txt | grep [url=http://www.activationlink.com]www.activationlink.com[/url]"
	set theResult to result
	
	(*Returns the result
	[url=http://www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd]www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd[/url]
	but also returns [url=http://www.activationlink.com]www.activationlink.com[/url] which is not in the email but in the do shell script line
	this means when I wget [url=http://www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfdwww.activationlink.com]www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfdwww.activationlink.com[/url] I get error
	when i wget it should look like [url=http://www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd]www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd[/url]
reason for grep [url=http://www.activationlink.com]www.activationlink.com[/url] because activation links are unique to the user or everytime requested*)
	
	
	do shell script " wget " & theResult
	--error ends here
	
end commands

is it possible to post the contents of a messages content so that we can play around with stripping the info out you need.

The email message looks exactly like this one but the link was changed.

grep returns www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd0923jkds9784filulwejd89dluisf and adds www.activationlink.com add the end of the string

I think im passing the wrong commands(still new to unix)

this is sorta like the problem I had with md5 where I couldn’t get just the md5 file

if you md5 /path/to/file -1st try
you get
“MD5 (/1.txt) = de0bdcb3b1746f99cf5d8b2ee1c8e595”

if you md5 -q /path/to/file/ 2nd -try
you get
“de0bdcb3b1746f99cf5d8b2ee1c8e595”

in this case im getting
www.activationlink.com/id/74jfJeo3kHenfus83jbdfsj388iosfd0923jkds9784filulwejd89dluisf
+
www.activationlink.com

no matter what I grep, it shows up at the end of the result.

I assume im passing the wrong commands or arugments just don’t know which ones will produce the line im asking for

From the text you posted, this works fine for me.
Are you sure that there is not another line somewhere in the email that has www.activationlink.com
Because thats the only way grep would put it in.

There is nothing in your grep statement to do otherwise.

Also why writing the content out??

just use:

using terms from application "Mail"
	on perform mail action with messages theMessages
		tell application "Mail"
			repeat with eachMessage in theMessages
				set thisContent to get content of eachMessage
				my commands(thisContent)
			end repeat
		end tell
	end perform mail action with messages
end using terms from

on commands(thisContent)
	set theResult to do shell script "echo " & quoted form of thisContent & " | grep [url=http://www.activationlink.com]www.activationlink.com[/url]"
	
	do shell script " wget " & theResult
end commands