Esempio n. 1
0
    def send(self,c):
        # Should be called with mutex acquired for c
        

        if self.thread:
            def rightthread(ts):
                for p in ts.aux_items:
                    if p.tag == AI_CAN_THREAD and p.data == '%s' % self.thread:
                        return 1

            possible_texts = messages_satisfying( rightthread )

            if possible_texts: # Any texts with this thread?
                possible_texts.reverse() # Take the latest
                
                self.miscinfo.comment_to_list.append(
                    kom.MICommentTo(kom.MIC_COMMENT,possible_texts[0]))

                # Make sure we only have one aux item of this type
                removelist = []
                for p in self.auxitems:
                    if p.tag == AI_CAN_THREAD and p.data == '%s' % self.thread:
                        removelist.append(p)
                for p in removelist:
                    self.auxitems.remove(p)

        kom.ReqCreateText(conn,
                          self.text,
                          self.miscinfo,
                          self.auxitems).response()
Esempio n. 2
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()
Esempio n. 3
0
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()
Esempio n. 4
0
    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
Esempio n. 5
0
    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,
                                    misc_info, aux_items).response()
#        for mark in marks:
#            if -1 == mark[0]:
#                break
#            kom.ReqAddComment(conn, mark[0], text_no).response()
        
        
        
        
        

    

Esempio n. 6
0
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"