Upload your Google Contacts VCF and get a T-Mobile compatible VCF


Upload your Google Contacts VCF and get a T-Mobile compatible VCF

Your Google Voice Number (just numbers):

Your Google Voice PIN (if required to place call from your cell phone):

Route calls through Google Voice:

About

Want to make placing calls through Google Voice easier? Are you on T-Mobile? Me too. This page gets your Google contacts into your T-Mobile phone, and optionally lets you make all phone numbers route through Google Voice.

Google’s VCF file is incompatible with the VCF files you can upload to my.t-mobile.com. This page does two quick search-and-replaces to make it work.

If you check the box and give your Google Voice number, it will convert each number from: 5551231234 to 17775435432p2p5551231234# where 17775435432 is your Google Voice number. The p is a pause, which will make it call Google Voice, wait a moment, press 2 to place a call, dial the number and press #.

Warning

Use at your own risk. I cannot be held responsible for data loss, misdialed numbers or other errors that may occur as a result of your use of this site, or your use of the resultant VCF file.

Code

Here’s the code I’m using

<?php

global $errmsg;

function goodFile(){
    global $errmsg;

    if($_FILES['gvcf']['error'] != 0){ $errmsg = "An upload error occurred!"; return false;}
    if($_FILES['gvcf']['type'] != 'text/directory'){ $errmsg = "The file is not a valid VCF file!"; return false;}
    if($_FILES['gvcf']['size'] > 450000){ $errmsg = "Too big!"; return false;}

    return true;
}

function cleanPhoneNumbers($matches){
    $cleanedNumber = preg_replace('/[^0-9]/','',$matches[2]);
    return $matches[1] . $cleanedNumber ."\n";
}

if($_FILES['gvcf'] && goodFile())
{
    $gv = file($_FILES['gvcf']['tmp_name'],FILE_IGNORE_NEW_LINES);

    // strip non numerics
    $gv = preg_replace_callback('/^(TEL;TYPE=.*:)(.*)$/','cleanPhoneNumbers',$gv);

    if($_POST['usegv'] == 'on' && $_POST['gvn'] != ""){
	$gvnumpluspin = $_POST['gvn'] . ($_POST['gvpin'] == '' ? '' : 'p' . $_POST['gvpin']);
	$gv = preg_replace('/^TEL;TYPE=(.*):+?([0-9]*)\s*$/','TEL;TYPE=\1:'.$gvnumpluspin.'p2p\2#',$gv);
	$filename = "tmo_gv_" . $_POST['gvn'] . ".vcf";
    } else {
	$filename = "tmo_gv_" . basename($_FILES['gvcf']['name']);
    }

    $find    = array('TYPE=CELL','EMAIL;TYPE=INTERNET','(',')','-');
    $replace = array('TYPE=cell,pref,voice,home','EMAIL;TYPE=INTERNET;TYPE=HOME','','','');
    $gv = str_replace($find,$replace,$gv);

    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=$filename");
    header("Content-Transfer-Encoding: binary");
    print implode("\n",$gv);
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
	<link rel='stylesheet' type='text/css' href='http://stuporglue.org/tako/page/style.css' media='screen'/>
	<title>Google Voice --&gt; T-Mobile</title>
	<?php include('/home/stuporgl/www/menu.php');?>
<h1>Upload your Google Contacts VCF and get a T-Mobile compatible VCF</h1>
<? if(isset($errmsg)){ print "<h2 style='color:red;'>$errmsg</h2>"; } ?>
<p>
<form action='http://stuporglue.org/gv/index.php' method='post' enctype='multipart/form-data'>
Your Google Contacts VCF file: <input type="file" name="gvcf"/><br/>
Your Google Voice Number (Optional): <input type='text' name="gvn"/> (15553331234) -- no spaces, dashes, parens, etc.<br/>
Your Google Voice PIN (if required to place call from your cell phone): <input type='password' name='gvpin'/><br/>
Route calls through Google Voice: <input type='checkbox' name='usegv'/><br/>
<input type='submit' value='Make new VCF!'/>
</form>
</p>
<h2>About</h2>
<p>
Want to make placing calls through Google Voice easier? Are you on T-Mobile? Me
too. This page gets your Google contacts into your T-Mobile phone, and optionally
lets you make all phone numbers route through Google Voice.
</p>
<p>
Google's VCF file is incompatible with the VCF files you can upload to
my.t-mobile.com. This page does <a href='http://hopedespite.blogspot.com/2008/12/how-to-export-gmail-contact-phone.html'>two quick search-and-replaces</a> to make it work.
</p>
<p>
If you check the box and give your Google Voice number, it will convert each number from:
<i>5551231234</i> to <i>17775435432p2p5551231234#</i> where 17775435432 is your
Google Voice number. The p is a pause, which will make it call Google Voice, wait a moment,
press 2 to place a call, dial the number and press #.
</p>
<h2>Warning</h2>
<p>
Use at your own risk. I cannot be held responsible for data loss, misdialed
numbers or other errors that may occur as a result of your use of this site,
or your use of the resultant VCF file.
</p>
<p>I do not keep, collect or record any of the information
submitted ot this site, however, this is not a secure (https) site.
</p>
<p>
This script has very little error checking. Please verify that the contents of
the downloaded file is correct before using it.
</p>
<?php include('/home/stuporgl/www/footer.php');
}

This entry was posted in Programming, Projects and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *