/** * @subpackage contacts/functions */ function fetch_gmail_contacts($config, $contact_store) { foreach (Hm_IMAP_List::dump(false, true) as $id => $server) { if ($server['server'] == 'imap.gmail.com' && array_key_exists('auth', $server) && $server['auth'] == 'xoauth2') { $results = imap_refresh_oauth2_token($server, $config); if (!empty($results)) { if (Hm_IMAP_List::update_oauth2_token($server_id, $results[1], $results[0])) { Hm_Debug::add(sprintf('Oauth2 token refreshed for IMAP server id %d', $server_id)); $updated++; $server = Hm_IMAP_List::dump($id); } } $url = 'https://www.google.com/m8/feeds/contacts/' . $server['user'] . '/full'; $contacts = parse_contact_xml(gmail_contacts_request($server['pass'], $url), $server['name']); if (!empty($contacts)) { $contact_store->import($contacts); } } } return $contact_store; }
public function process() { $active = array(); if (array_key_exists('imap_server_ids', $this->request->post)) { $active = explode(',', $this->request->post['imap_server_ids']); } if (array_key_exists('imap_server_id', $this->request->post)) { $active[] = $this->request->post['imap_server_id']; } $updated = 0; foreach ($active as $server_id) { $server = Hm_IMAP_List::dump($server_id, true); if (array_key_exists('auth', $server) && $server['auth'] == 'xoauth2') { $results = imap_refresh_oauth2_token($server, $this->config); if (!empty($results)) { if (Hm_IMAP_List::update_oauth2_token($server_id, $results[1], $results[0])) { Hm_Debug::add(sprintf('Oauth2 token refreshed for IMAP server id %d', $server_id)); $updated++; } } } } if ($updated > 0) { $servers = Hm_IMAP_List::dump(false, true); $this->user_config->set('imap_servers', $servers); $this->session->set('user_data', $this->user_config->dump()); } }