This repository was archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvcard.py
162 lines (148 loc) · 5.95 KB
/
vcard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Console Jabber Client
# Copyright (C) 2004-2010 Jacek Konieczny
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Normative reference: JEP-0054
import os
from cjc.plugin import PluginBase
from cjc import ui
import pyxmpp
from pyxmpp.jabber import VCARD_NS,VCard
class Plugin(PluginBase):
def __init__(self,app,name):
PluginBase.__init__(self,app,name)
ui.activate_cmdtable("vcard",self)
def session_started(self,stream):
#self.cjc.stream.set_iq_get_handler("query",VCARD_NS,self.vcard_get)
#self.cjc.disco_info.add_feature(VCARD_NS)
pass
def cmd_whois(self,args):
if not self.cjc.stream:
self.error("Connect first!")
return
target=args.shift()
if target:
jids = self.cjc.get_users(target)
if not jids:
return
else:
jids = [self.cjc.jid.bare()]
for jid in jids:
iq=pyxmpp.Iq(to_jid=jid,stanza_type="get")
q=iq.new_query(VCARD_NS, "vCard")
self.cjc.stream.set_response_handlers(iq,self.vcard_response,self.vcard_error)
self.cjc.stream.send(iq)
def vcard_response(self,stanza):
try:
node=stanza.get_query()
if node:
vcard=VCard(node)
else:
vcard=None
except (ValueError,),e:
vcard=None
if vcard is None:
self.error(u"Invalid vCard received from "+stanza.get_from().as_unicode())
return
self.cjc.set_user_info(stanza.get_from(),"vcard",vcard)
msg = u"vCard for %s:\n" % (unicode(stanza.get_from()),)
msg+=u" Full name: %s\n" % (vcard.fn.value)
if vcard.n.given:
msg += u" Given name: %s\n" % (vcard.n.given)
if vcard.n.middle:
msg += u" Middle name: %s\n" % (vcard.n.middle)
if vcard.n.family:
msg += u" Family name: %s\n" % (vcard.n.family)
for title in vcard.title:
msg += u" Title: %s\n" % (title.value)
for role in vcard.role:
msg += u" Role: %s\n" % (role.value)
for email in vcard.email:
if "internet" in email.type:
msg += u" E-Mail: %s\n" % (email.address,)
for nick in vcard.nickname:
msg += u" Nick: %s\n" % (nick.value,)
for photo in vcard.photo:
if photo.uri:
msg += u" Photo: %s\n" % (photo.uri,)
else:
msg += u" Photo: cannot display\n"
for logo in vcard.logo:
if logo.uri:
msg += u" Logo: %s\n" % (logo.uri,)
else:
msg += u" Logo: cannot display\n"
for bday in vcard.bday:
msg += u" Birthday: %s\n" % (bday,)
for adr in vcard.adr:
msg += u" Address (%s):\n" % (u", ".join(adr.type),)
if adr.pobox:
msg += u" PO Box: %s\n" % (adr.pobox,)
if adr.extadr:
msg += u" %s\n" % (adr.extadr,)
if adr.street:
msg += u" Street: %s\n" % (adr.street,)
if adr.locality:
msg += u" Locality: %s\n" % (adr.locality,)
if adr.region:
msg += u" Region: %s\n" % (adr.region,)
if adr.pcode:
msg += u" Postal code: %s\n" % (adr.pcode,)
if adr.ctry:
msg += u" Country: %s\n" % (adr.ctry,)
for label in vcard.label:
msg += u" Address label (%s):\n" % (u", ".join(label.type),)
for l in label.lines:
msg += u" %s\n" % (l,)
for tel in vcard.tel:
msg += u" Phone (%s): %s\n" % (u", ".join(tel.type), tel.number)
for jabberid in vcard.jabberid:
msg += u" JID: %s\n" % (unicode(jabberid.value),)
for mailer in vcard.mailer:
msg += u" Mailer: %s\n" % (mailer.value,)
for tz in vcard.tz:
msg += u" Time zone: %s\n" % (tz.value,)
for geo in vcard.geo:
msg += u" Geolocation: %s, %s\n" % (geo.lat, geo.lon)
for org in vcard.org:
msg += u" Organization: %s\n" % (org.name, )
if org.unit:
msg += u" Org. unit: %s\n" % (org.unit, )
for categories in vcard.categories:
msg += u" Categories: %s\n" % (u", ".join(categories.keywords),)
for note in vcard.note:
msg += u" Note: %s\n" % (note.value,)
for sound in vcard.sound:
if sound.uri:
msg += u" Sound: %s\n" % (sound.uri,)
else:
msg += u" Sound: cannot play\n"
for uid in vcard.uid:
msg += u" User id: %s\n" % (uid.value,)
for url in vcard.url:
msg += u" URL: %s\n" % (url.value,)
for desc in vcard.desc:
msg += u" Description: %s\n" % (desc.value,)
self.info(msg)
def vcard_error(self,stanza):
err=stanza.get_error()
self.error(u"vCard query error from %s: %s" % (stanza.get_from(),
err.get_message()))
ui.CommandTable("vcard",50,(
ui.Command("whois",Plugin.cmd_whois,
"/whois jid",
"Displays information about an entity.",
("user",)),
)).install()
# vi: sts=4 et sw=4