5

我用谷歌搜索了很多,但不幸的是无法提出一个可行的解决方案。我有一个使用 SleekXMPP 模块的 Python 客户端,我想将 PNG 文件发送到 Pidgin 客户端。AFAIK,还没有实现 Jingle 扩展,但是有一些方法使用IBBOOB并且BOB对我不起作用。我已经尝试过 XEP 0047023100950096进行谈判。

我将 Pidgin 设置为自动接受来自某个 JID 的文件。

有没有办法使用 SleekXMPP 做到这一点?

ps这本书XMPP: The definitive guide也没有给我任何线索:/

谢谢。

代码

def upload_files_tgz(self, archivename, files, removearch=True):
    # tar file name and mimetype (b for binary)
    bfilename = "{0}.tar.gz".format(archivename)
    bfilemime = "application/x-gzip";
    # create a compressed tgz archive
    tar = tarfile.open(bfilename, "w:gz" )
    if files:
        for f in files:
            tar.add(f)
    tar.close()

    with open(bfilename, "rb") as compressed_file:
        bin_output = compressed_file.read()

    cid = self.xmpp_bot['xep_0231'].set_bob(bin_output, bfilemime)
    msg = self.xmpp_bot.Message()
    msg['to'] = self.get_xmpp_server_full_jid()
    msg['bob']['cid'] = cid
    msg['bob']['type'] = bfilemime
    msg['bob']['data'] = bin_output
    msg.send()

    if removearch == True:
        os.remove(bfilename)

def upload_image(self, filename, mimetype='image/png', message=None):
    m = self.xmpp_bot.Message()
    m['to'] = self.get_xmpp_server_full_jid()
    m['type'] = 'chat'
    with open(filename, 'rb') as img_file:
        img = img_file.read()
    if img:
        cid = self.xmpp_bot['xep_0231'].set_bob(img, mimetype)
        if message:
            m['body'] = message
        m['html']['body'] = '<img src="cid:%s" />' % cid
        m.send()
4

0 回答 0