Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'incoming mail server' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
incoming mail server
Authored by: shreddiez on Jan 21, '03 03:51:07PM
Based on mattw's smtp server change, here's my script for pop server change, which also changes the port. The main differnce is that the applescript parses the settings to spilt up the server and port, then also sets the port using "set server port", but not "set port" as the Mail dictionary would have you believe :/
#!/usr/bin/perl -w use strict; # The Network Location name to POP server hostname mapping: my $pop_for_location = { Home" => "popserver.domain.com:110", "Uni" => "localhost:1110" }; # These are the account names to change my $accounts_to_change = [ "Default" ]; my $location = &get_location_from_scutil() || ""; unless(exists $pop_for_location->{$location}) { die "The location is unknown"; } my $le = "r"; open(APPLESCRIPT, "| osascript"); while(my $line = ) { chomp $line; if($line =~ m/property/) { if($line =~ m/%popserver%/) { my $newserver = '"' . $pop_for_location->{$location} . '"'; $line =~ s/%popserver%/$newserver/; } elsif($line =~ m/%accounts%/) { my $account_string = '"'. join('","', @{$accounts_to_change}) .'"'; $line =~ s/%accounts%/$account_string/; } } print APPLESCRIPT $line, $le; } close(APPLESCRIPT); sub get_location_from_scutil { my @scutil = `scutil /dev/null open show Setup:/ close end_scutil`; my @matches = map { m/UserDefinedName : (.*)/ } @scutil; if(@matches == 1) { return $matches[0]; } else { return undef; } } __DATA__ property newPOPAddress : %popserver% property accountsToChange : {%accounts%} set theDelimiter to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set the item_list to every text item of newPOPAddress set newPOPServer to item 1 of item_list set newPOPPort to item 2 of item_list as integer set AppleScript's text item delimiters to theDelimiter on weWantToChangeThisAccount(theAccount) set theResult to false --set theAccountName to name of theAccount --display dialog "this is " & theAccountName repeat with eachAccount in accountsToChange if (name of theAccount is equal to eachAccount as string) then set theResult to true end if end repeat return theResult end weWantToChangeThisAccount on theAccountAlreadyHasThisServer(CurrentServer, newServer) set theResult to false if (CurrentServer as string is equal to newServer as string) then set theResult to true end if return theResult end theAccountAlreadyHasThisServer set anAccountWasUpdated to "no" --if (theSMTPServer is not equal to false) then tell application "Mail" set everyAccount to every account repeat with eachAccount in everyAccount if (my weWantToChangeThisAccount(eachAccount)) then set currentPOPServer to server name of eachAccount if (my theAccountAlreadyHasThisServer(currentPOPServer, newPOPServer)) then -- do nothing else set server name of eachAccount to newPOPServer set server port of eachAccount to newPOPPort --display dialog "change " & name of eachAccount & " to " & name of theSMTPServer set anAccountWasUpdated to name of eachAccount end if end if end repeat end tell --end if return anAccountWasUpdated


[ Reply to This | # ]