sapo mail webservices

33
SAPO Mail - Webservices Nuno Loureiro <[email protected] > Carlos Pires <[email protected] > André Luís <[email protected] > 14 de Novembro 2007

Upload: codebits

Post on 28-Jan-2015

137 views

Category:

Technology


1 download

DESCRIPTION

SAPO Mail, API de acesso ao Webmail

TRANSCRIPT

Page 2: SAPO Mail WebServices

SAPO Mail - Webservices

Arquitectura

Exemplos Práticos

Contactos

Mail

Credenciais

Aspectos Gerais

Page 3: SAPO Mail WebServices

Arquitectura do Webmail

Page 4: SAPO Mail WebServices

SAPO Mail - Webservices

Aspectos Gerais

Exemplos Práticos

Contactos

Mail

Credenciais

Arquitectura

Page 6: SAPO Mail WebServices

Mail Webservices - Aspectos Gerais

End-Point:http://services.sapo.pt/Mail

WSDL:http://services.sapo.pt/Metadata/Contract/Mail

Namespace:http://services.sapo.pt/definitions

Exemplo Prático:http://services.mail.sapo.pt/codebits

Operator (Firefox):http://addons.mozilla.org/en-US/firefox/addon/4106

User-script para Operator (Firefox):http://services.mail.sapo.pt/operator/js/sapomail.js

Page 7: SAPO Mail WebServices

SAPO Mail - Webservices

Credenciais

Exemplos Práticos

Contactos

Mail

Aspectos Gerais

Arquitectura

Page 8: SAPO Mail WebServices

Mail Webservices - Credenciais - Objecto ESBCredentials1

• ESBUsername• ESBPassword

ESBCredentials

Usado para a autenticação nos webservices do mail;

class ESBCredentials { public $ESBUsername; //string public $ESBPassword; //string}

Todas as operações dos webservices do mail requerem a definição de um SOAP Header com as credenciais do utilizador.

Page 9: SAPO Mail WebServices

SAPO Mail - Webservices

Mail

Exemplos Práticos

Contactos

Credenciais

Aspectos Gerais

Arquitectura

Page 10: SAPO Mail WebServices

Mail Webservices - Mail - Objectos1

• Status• ArrayOfLastMail

Mailbox

Status• Total• Unseen• Recent

PageInfo• PageNumber• RecordsCount• MaxRecords

LastMail• MessageId• FromName• FromEMail• Subject• Date• Seen

• Recent• Answered• Deleted• Flagged• Size (in bytes)

• PageInfo• LastMail

ArrayOfLastMail

Page 11: SAPO Mail WebServices

Mail Webservices - Mail - Operações (1)

GetStatus

class Status { public $Total; //int public $Unseen; //int public $Recent; //int}

GetStatus

Page 12: SAPO Mail WebServices

Mail Webservices - Mail - Operações (2)

GetLastMails

class ArrayOfLastMail { public $PageInfo; public $LastMail = array();}

class LastMail { public $MessageId; //int (imap uid) public $FromName; //string public $FromEMail; //string public $Subject; //string public $Date; //string public $Seen; //boolean public $Recent; //boolean public $Answered; //boolean public $Deleted; //boolean public $Flagged; //booelan public $Size; //int (in bytes)}

class PageInfo { public $PageNumber; //int public $RecordsCount; //int public $MaxRecords; //int}

GetLastMails• page (1 by default)• limit (10 by default, max 50)

Headers das mensagens pedidas;

Ordenação: ARRIVAL DATE DESC

Page 13: SAPO Mail WebServices

Mail Webservices - Mail - Operações (3)

GetMailbox

class Mailbox { public $Status; public $ArrayOfLastMail;} class ArrayOfLastMail {

public $PageInfo; //PageInfo public $LastMail = array(); //LastMail}

class Status { public $Total; //int public $Unseen; //int public $Recent; //int}

GetMailbox• page (1 by default)• limit (10 by default, max 50)

Headers das mensagens pedidas;

Ordenação: ARRIVAL DATE DESC

Page 14: SAPO Mail WebServices

Mail Webservices - Mail

Page 15: SAPO Mail WebServices

SAPO Mail - Webservices

Contactos

Exemplos Práticos

Credenciais

Mail

Aspectos Gerais

Arquitectura

Page 16: SAPO Mail WebServices

Mail Webservices - Contactos - Objectos1

• ContactInfo• Contact

ArrayOfContact

Contact ContactInfo• ContactId• Name• Alias• Email• HomeAddress• WorkAddress• HomePhone• WorkPhone

• CellPhone• Fax• Title• Company• Notes• PGPPublicKey• SMimePublicKey• FreeBusyURL

• RecordsCount• SearchExpression (opcional)

Page 17: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (1)

ListAllContacts

class Contact { public $ContactId; //string public $Name; //string public $Alias; //string public $Email; //string public $HomeAddress; //string public $WorkAddress; //string public $HomePhone; //string public $WorkPhone; //string public $CellPhone; //string public $Fax; //string public $Title; //string public $Company; //string public $Notes; //string public $PGPPublicKey; //string public $SMimePublicKey; //string public $FreeBusyURL; //string}

class ArrayOfContact { public $ContactInfo; public $Contact = array();}

class ContactInfo { public $RecordsCount; //int public $SearchExpression; //string}

ListAllContacts

Page 18: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (2)

GetContact

class Contact { public $ContactId; //string public $Name; //string public $Alias; //string public $Email; //string public $HomeAddress; //string public $WorkAddress; //string public $HomePhone; //string public $WorkPhone; //string public $CellPhone; //string public $Fax; //string public $Title; //string public $Company; //string public $Notes; //string public $PGPPublicKey; //string public $SMimePublicKey; //string public $FreeBusyURL; //string}

GetContact• ContactID (string)

Page 19: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (3)

AddContact

057259c0271b5cf71bb8e9be7ace49e2

AddContact• Contact (object)

Campo gerado pelo webservice:

ContactId; Obrigatório:

Name.

ContactId (hash md5)

Page 20: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (4)

SetContact

true

SetContact• ContactID (string)• Contact (object)

Campo ignorado pelo webservice:

ContactId;

false

Sucesso Erro

Page 21: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (5)

SearchContact

class Contact { public $ContactId; //string public $Name; //string public $Alias; //string public $Email; //string public $HomeAddress; //string public $WorkAddress; //string public $HomePhone; //string public $WorkPhone; //string public $CellPhone; //string public $Fax; //string public $Title; //string public $Company; //string public $Notes; //string public $PGPPublicKey; //string public $SMimePublicKey; //string public $FreeBusyURL; //string}

class ArrayOfContact { public $ContactInfo; public $Contact = array();}

class ContactInfo { public $RecordsCount; //int public $SearchExpression; //string}

SearchContact• SearchExpression (string != ‘’) Nome

E-mail

Page 22: SAPO Mail WebServices

Mail Webservices - Contactos - Operações (6)

DeleteContactDeleteContact

• ContactID (string)

true false

Sucesso Erro

Page 23: SAPO Mail WebServices

Mail Webservices - Contactos

Page 24: SAPO Mail WebServices

Mail Webservices - Contactos

Page 25: SAPO Mail WebServices

SAPO Mail - Webservices

Exemplos Práticos

Contactos

Credenciais

Mail

Aspectos Gerais

Arquitectura

Page 26: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - SOAP Request

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.sapo.pt/definitions"> <SOAP-ENV:Header> <ns1:ESBCredentials> <ns1:ESBUsername>[email protected]</ns1:ESBUsername> <ns1:ESBPassword>somepass</ns1:ESBPassword> </ns1:ESBCredentials> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:GetMailbox> <ns1:page>1</ns1:page> <ns1:limit>10</ns1:limit> </ns1:GetMailbox> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 27: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - SOAP Request

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.sapo.pt/definitions"> <SOAP-ENV:Header> <ns1:ESBCredentials> <ns1:ESBUsername>[email protected]</ns1:ESBUsername> <ns1:ESBPassword>somepass</ns1:ESBPassword> </ns1:ESBCredentials> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:ListAllContacts/> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 28: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - PHP5 Client Example

<?php

require_once dirname(__FILE__) . '/Mail_client_conf.php'; // Configrequire_once dirname(__FILE__) . '/Mail_types.php'; // Class types

$user = '[email protected]';$pass = 'somepass';

$ESBC = new ESBCredentials_t();$ESBC->ESBUsername = $user;$ESBC->ESBPassword = $pass;

$GetMailbox = new GetMailbox_t();$GetMailbox->page = 1;$GetMailbox->limit = 10;

$paramMailbox = (isset($GetMailbox)) ? array('parameters' => $GetMailbox) : array();

// [ ---> Continua ]

Page 29: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - PHP5 Client Example (2)

$client = new SoapClient( /* This should be local, avoid one network call */ 'http://services.sapo.pt/Metadata/Contract/Mail', array('location' => "http://services.sapo.pt/Mail", 'classmap' => $classmap));

$header = new SoapHeader('http://services.sapo.pt/definitions', 'ESBCredentials', $ESBC);

try { $response = $client->__soapCall('GetMailbox', $paramMailbox, null, $header); /* Your Code Here */

} catch (SoapFault $e) { $text = (!$e->getMessage()) ? $e->faultstring : $e->getMessage(); echo "SOAP FAULT: $text\n";}

?>

Page 30: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - PHP CodeGenerator

<?php

require_once dirname(__FILE__) . '/Mail_client_conf.php';require_once dirname(__FILE__) . '/Mail_client.php';

$client = new Mail_client($conf);$client->makeHeader('[email protected]', 'somepass');

/* GetMailbox(page, limit) */$response = $client->GetMailbox(1, 10);

/* ListAllContacts *///$response = $client->ListAllContacts();

/* AddContact(Contact) *///$Contact = new Contact_t();//$Contact->Name = 'somename';// ...//$response = $client->AddContact($Contact);

/* Your Code Here */?>

Page 31: SAPO Mail WebServices

Mail Webservices - Exemplos Práticos - Em Acção (1)

Agora é tempo de ver tudo isto em acção:Listagem de Mails e Contactos:

Webservices:GetMailbox;ListAllContacts;

Importação de contactos para o webmail:Webservices:

AddContact;Ferramentas:

Microformatos;Operator (extensão Firefox);

Page 33: SAPO Mail WebServices

http://mail.blogs.sapo.pt/