–modify this to name of every possible field
property all_fields : {“personal_name”, “personal_address”, “personal_email”, “personal_invite”, “personal_activities”, ¬
“q1”, “q1a”, “q1b”, “q1c”, “q1d”, “q1e”, “q1f”, “q1g”, ¬
“q2”, “q2a”, “q2b”, “q2c”, “q2d”, “q2e”, “q2f”, “q2g”, ¬
“q3”, “q3a”, “q3b”, “q3c”, “q3d”, “q3e”, “q3f”, “q3g”, ¬
“q4”, “q4a”, “q4b”, “q4c”, “q4d”, “q4e”, “q4f”, “q4g”, ¬
“q5”, “q5a”, “q5b”, “q5c”, “q5d”, “q5e”, “q5f”, “q5g”, ¬
“q6”, “q6a”, “q6b”, “q6c”, “q6d”, “q6e”, “q6f”, “q6g”, ¬
“q7”, “q7a”, “q7b”, “q7c”, “q7d”, “q7e”, “q7f”, “q7g”, ¬
“q8”, “q8a”, “q8b”, “q8c”, “q8d”, “q8e”, “q8f”, “q8g”, ¬
“q9”, “q9a”, “q9b”, “q9c”, “q9d”, “q9e”, “q9f”, “q9g”, ¬
“q10”, “q10a”, “q10b”, “q10c”, “q10d”, “q10e”, “q10f”, “q10g”, ¬
“q11”, “q11a”, “q11b”, “q11c”, “q11d”, “q11e”, “q11f”, “q11g”, ¬
“q12”, “q12a”, “q12b”, “q12c”, “q12d”, “q12e”, “q12f”, “q12g”}
set the_csv to “”
–you need a routine for iterating through all the mail messages and getting the_content:
(
repeat with i from 1 to count of the_messages
--get the_content
set the_csv to the_csv & (my get_csv(the_content))
end repeat
return the_csv
)
set the_content to “SoupermailConf = /zyen/msc/sf7.con
next = finish
personal_activities = Only prize draw entry
personal_address = Street
Town
County Postcode
personal_email = xxx@hotmail.com
personal_invite = no
personal_name = Xxxxxx
q10 = in a relationship
q11 = young children
q12b = Eat out at restaurants at least once a month
q12j = buy environmentally friendly ethically produced products
q1a = agree
q1b = agree
q1c = strongly disagree
q1d = strongly disagree
q1e = strongly agree
q1f = agree
q1g = agree
q2a = no
q2b = no
q2c = yes
q2d = no
q3g = not willing to join
q6r = not a member of any
q7e = General magazines newspapers
q7h = TV documentaries
q7i = TV news
q8 = male
q9 = 41 65
q_ver = 1”
my [color=green]get_csv/color
on [color=green]get_csv/color
set AppleScript’s text item delimiters to {ASCII character 10, ASCII character 13, return}
set the_data to (every text item of the_content) as list
set AppleScript’s text item delimiters to {“”}
set concat_data to {}
set i to 1
repeat until i = (count of the_data)
set the_item to (item i of the_data)
if the_item starts with “personal_address” then
set the_item to the_item & " " & (item (i + 1) of the_data) & " " & (item (i + 2) of the_data)
set i to i + 3
else
set i to (i + 1)
end if
copy the_item to end of concat_data
end repeat
copy {{}, {}} to {the_fields, the_data}
repeat with i from 1 to count of concat_data
set the_item to item i of concat_data
set AppleScript’s text item delimiters to {" = “}
copy {(text item 1 of the_item), (text item 2 of the_item)} to {end of the_fields, end of the_data}
set AppleScript’s text item delimiters to {”"}
end repeat
[color=red]set[/color] [color=green]the_csv[/color] [color=red]to[/color] ""
[color=red]set[/color] [color=green]field_count[/color] [color=red]to[/color] [color=blue]count[/color] [color=red]of[/color] [color=green]all_fields[/color]
[color=red]repeat[/color] [color=red]with[/color] [color=green]i[/color] [color=red]from[/color] 1 [color=red]to[/color] [color=green]field_count[/color]
[color=red]set[/color] [color=green]the_csv[/color] [color=red]to[/color] [color=green]the_csv[/color] & ([color=red]my[/color] [color=green]return_pair_match[/color](([color=blue]item[/color] [color=green]i[/color] [color=red]of[/color] [color=green]all_fields[/color]), [color=green]the_fields[/color], [color=green]the_data[/color], ""))
[color=red]if[/color] [color=green]i[/color] < [color=green]field_count[/color] [color=red]then[/color]
[color=red]set[/color] [color=green]the_csv[/color] [color=red]to[/color] [color=green]the_csv[/color] & ","
[color=red]else[/color]
[color=red]set[/color] [color=green]the_csv[/color] [color=red]to[/color] [color=green]the_csv[/color] & [color=blue]return[/color]
[color=red]end[/color] [color=red]if[/color]
[color=red]end[/color] [color=red]repeat[/color]
[color=red]return[/color] [color=green]the_csv[/color]
end get_csv
on return_pair_match(the_match_val, list_a, list_b, return_no_match)
repeat with i from 1 to count of list_a
if item i of list_a = the_match_val then return item i of list_b
end repeat
return return_no_match
end return_pair_match
–this script was automatically tagged for
–color coded syntax by Script to Markup Code
–written by Jon Nathan