コード例 #1
0
def write_article(sender, subject, text):
    misc_info = kom.CookedMiscInfo()
    misc_info.recipient_list.append(
        kom.MIRecipient(kom.MIR_TO, TARGET_CONFERENCE))
    misc_info.recipient_list.append(kom.MIRecipient(kom.MIR_TO, sender))

    aux_items = []
    kom.ReqCreateText(conn, subject + "\n" + reformat_text(text), misc_info,
                      aux_items).response()
コード例 #2
0
ファイル: telefonist.py プロジェクト: jaydeepraj/websites
def send_letter( to, conn, subj, message ):
    "Send a letter to the given person with subj as Subject and message as body"
    
    misc_info = kom.CookedMiscInfo()
    misc_info.recipient_list.append(kom.MIRecipient( kom.MIR_TO, int(to) ))

    aux_items = [] # FIXME!

    # creating-software [15] (text)

    ai = kom.AuxItem(kom.AI_CREATING_SOFTWARE)
    ai.data = "telefonisten %s" % VERSION
    aux_items.append(ai)

    ai2 = kom.AuxItem(kom.AI_CONTENT_TYPE)
    ai2.data = "text/plain"
    aux_items.append(ai2)
    
    text = subj + "\n" + message  
    kom.ReqCreateText(conn, text, misc_info, aux_items).response()
コード例 #3
0
ファイル: komsession.py プロジェクト: adamel/httpkom
    def create_text(self, komtext):
        misc_info = kom.CookedMiscInfo()

        if komtext.recipient_list is not None:
            for rec in komtext.recipient_list:
                if rec is not None:
                    misc_info.recipient_list.append(rec)

        if komtext.comment_to_list is not None:
            for ct in komtext.comment_to_list:
                if ct is not None:
                    misc_info.comment_to_list.append(ct)

        print misc_info.to_string()

        mime_type = mimeparse.parse_mime_type(komtext.content_type)
        # Because a text consists of both a subject and body, and you
        # can have a text subject in combination with an image, a
        # charset is needed to specify the encoding of the subject.
        mime_type[2]['charset'] = 'utf-8'
        content_type = mime_type_tuple_to_str(mime_type)

        # TODO: how would this work with images?
        fulltext = str()
        fulltext += komtext.subject.encode('utf-8') + "\n"
        if (mime_type[0] == 'text'):
            fulltext += komtext.body.encode('utf-8')
        else:
            fulltext += komtext.body

        aux_items = []
        aux_items.append(
            kom.AuxItem(kom.AI_CREATING_SOFTWARE,
                        data="%s %s" %
                        (self.client_name, self.client_version)))
        aux_items.append(kom.AuxItem(kom.AI_CONTENT_TYPE, data=content_type))

        text_no = kom.ReqCreateText(self.conn, fulltext, misc_info,
                                    aux_items).response()
        return text_no
コード例 #4
0
                                  conn.textstats[mark[0]].no_of_chars).response()
        subj = textdata.split('\n')[0]
					
	for r in conn.textstats[mark[0]].misc_info.recipient_list:
	    conf = r.get_tuples()[0][1]	
	    txt+=" "*len("<text %d> " % mark[0])+ \
	         "<möte %d: %s>" % (conf, conn.conferences[conf].name)+"\n"
        txt+=" "*len("<text %d> " % mark[0])+subj+"\n"

    if verbose:
        print txt

# kom.ReqAddComment(conn, 234, 235).response()

    if reportmeeting:
        misc_info = kom.CookedMiscInfo()
        misc_info.recipient_list.append(kom.MIRecipient(type=kom.MIR_TO,
                                                        recpt=reportmeeting))

        aux_items = []
        
        for mark in marks:
            if -1 == mark[0]:
                break
            aux_items.append(kom.AuxItem(kom.AI_CROSS_REFERENCE,
                                         "T%d %d markeringar." % (mark[0],
                                                                  mark[1])))
#            misc_info.comment_to_list.append(kom.MICommentIn(mark[0]))
        

        text_no = kom.ReqCreateText(conn, "Markeringsstatistik\n"+txt,
コード例 #5
0
    def got_message(self,j,m):
        # We should have lock for self.mutex

        log( "%s got message from %s." % (m.getTo(), m.getFrom()) )

        if not self.is_ignored(m.getFrom()):
            sendmsg = 0
            sendletter = 0
                       
            if self.conf['messages_only'] or \
               (not m.getThread() and not m.getSubject()) and \
               m.getType() != 'error' or m.getType() == 'groupchat':                   
                sendmsg = 1
                subj = u""

                if m.getSubject():
                    subj = u" (ang: %s)" % m.getSubject()
                    
                msg = u"%s%s: %s" % (
                    utf8_d(self.msg_sender(m.getFrom())),
                    subj,
                    utf8_d(m.getBody()))

            elif m.getType() == 'error':
                sendmsg = 1
                msg = u"FEL! Ditt meddelande till %s misslyckades: Fel '%s' (%s) " % (
                    utf8_d(self.msg_sender(m.getFrom())),
                    utf8_d(m.getError()),
                    utf8_d(m.getErrorCode()))

            elif m.getThread() or (not m.getType() and m.getSubject()):
                sendletter = 1
                
                if m.getSubject():
                    msg = u"%s\n%s" % (m.getSubject(), m.getBody())
                else:
                    msg = u"Meddelande från %s\n%s" % (self.msg_sender(m.getFrom()),
                                                       m.getBody())

                mi = kom.CookedMiscInfo()
                mi.recipient_list.append(kom.MIRecipient( kom.MIR_TO, self.me ))
                mi.recipient_list.append(kom.MIRecipient( kom.MIR_TO, daemon_person ))

                ai = []
                aient = kom.AuxItem(kom.AI_CREATING_SOFTWARE)
                aient.data = u"Canidius %s " % VERSION
                ai.append( aient )

                if m.getThread():
                    # TODO: Should really use private aux-items
                    aient = kom.AuxItem(AI_CAN_THREAD)
                    aient.data = u"%s" % m.getThread()
                    aient.flags.inherit = 1
                    ai.append(aient)

                aient = kom.AuxItem(kom.AI_CONTENT_TYPE)
                aient.data = u"text/plain;charset=utf-8"
                ai.append(aient)

                aient = kom.AuxItem(kom.AI_MX_FROM)
                aient.data = m.getFrom().getStripped()
                ai.append(aient)

                if self.uid_to_alias( m.getFrom().getStripped() ) != str(m.getFrom().getStripped()):
                    aient = kom.AuxItem(kom.AI_MX_AUTHOR)
                    aient.data = u"%s" % (self.uid_to_alias( m.getFrom().getStripped()))
                    ai.append(aient)

                aient = kom.AuxItem(AI_CAN_FROM)
                aient.data = u"%s" % m.getFrom()
                ai.append(aient)

                aient = kom.AuxItem(kom.AI_MX_TO)
                aient.data = u"%s" % m.getTo().getStripped()
                ai.append(aient)

                aient = kom.AuxItem(AI_CAN_TO)
                aient.data = u"%s" % m.getTo()
                ai.append(aient)


            else:
                sendmsg = 1
                msg = u"Konstigt meddelande, rått: %s " % repr(m)

            if sendmsg:
                lock(komsendq_m)                
                komsendq.put(kommessage(self.me, l1_e(msg)))
                unlock(komsendq_m)

            if sendletter:
                lock(komsendq_m)
                komsendq.put(komtext(utf8_e(msg), mi, ai, m.getThread()))
                unlock(komsendq_m)
コード例 #6
0
ファイル: snobben.py プロジェクト: jaydeepraj/websites
def send_comment( conn, to, subj, message, fromname, fromaddr, comment ):
    "Send a letter to the given conference with subj as Subject and message as body"

    print "Sending comment, get lock"
    conn.rlock.acquire()

    misc_info = kom.CookedMiscInfo()
    print "Cooked MI OK"
    misc_info.recipient_list.append(kom.MIRecipient( kom.MIR_TO, int(to) ))
    print "Fixed recipient"
    
    if comment and time.time() - conn.conferences[ to ].last_written.to_python_time() < 10*60:
        print "We shall comment"
        c = conn.conferences[ to ]

        author = 0
        authors = ""
        
        if message[:message.find(":")] in conn.authors.keys():
            author = conn.authors[ message[:message.find(":")] ] #
        else:
            r = re.compile( r"^[^ ]*:" ) # Match destination handle
            m = r.match( message )

            print m
            if m:
                if m.start() == 0 and m.end() != 0: #Sensible
                    authors = message[:m.end()-1]
            
        print "Got conf info"
        print "%d, %d, %d" % (to, c.first_local_no, 255)

        print message
        print author
        print authors
        
        tno = 0
        # Ignore old messages the dirty way 
        try:
            tnomap = kom.ReqLocalToGlobal(conn, to,
                                          max(1,
                                              c.first_local_no+c.no_of_texts-255),
                                          255).response()

            print "Got local-to-global mapping"
 
            for p in tnomap.list:
                if author or authors:       # Not a comment to anybody particular?
                    ts = conn.textstats[ p[1] ]
                    if author == ts.author:
                        tno = max( p[1], tno )
                    else:                             # Imported comment?
                        for ai in ts.aux_items:
                            if ai.tag == kom.AI_MX_AUTHOR and ai.data == authors:
                                tno = p[1]
                                # Remove header
                                if message[:m.end()-1] == authors: #Only remove the first
                                    print "Msg %s" % message
                                    message = message[ m.end(): ].strip()
                                    print "msg %s" % message


                else:
                    tno = max( p[1], tno)


        except kom.NoSuchLocalText:
            pass

        print message
        #Make it a comment?
        if tno:
            misc_info.recipient_list.append(kom.MICommentTo( kom.MIC_COMMENT, int(tno) ))

        if author and tno: # Found the text and made a comment link? remove foo:
            message = message[message.find(":")+1:].strip()
        print "Added comment info"
        
    print "Checked whatever to comment OK"
    aux_items = [] # FIXME!

    # creating-software [15] (text)

    ai = kom.AuxItem(kom.AI_CREATING_SOFTWARE)
    ai.data = "snobben %s" % KOMVERSION
    aux_items.append(ai)
    print "First aux"
        
    ai2 = kom.AuxItem(kom.AI_CONTENT_TYPE)
    ai2.data = "text/plain"
    aux_items.append(ai2)

    print "Second"

    ai = kom.AuxItem(kom.AI_MX_FROM)
    ai.data = fromaddr
    aux_items.append(ai)
    print "First aux"

    ai = kom.AuxItem(kom.AI_MX_AUTHOR)
    ai.data = fromname
    aux_items.append(ai)
    print "First aux"

    text = subj + "\n" + message  
    kom.ReqCreateText(conn, text, misc_info, aux_items).response()
    print "Sent!"
    conn.rlock.release()
    print "Sending comment, release lock"