Beispiel #1
0
 def get_XPAT(self, group_name, header, pattern, start_id, end_id='ggg'):
     # XXX: need to actually check for the header values being passed as
     # XXX: not all header names map to column names on the tables
     table_name = self.get_table_name(group_name)
     stmt = """
             SELECT
                 A.id,
                 parent,
                 author,
                 email,
                 subject,
                 DATE_PART('epoch', datestamp) AS datestamp,
                 B.body
             FROM
                 %s A, 
                 %s_bodies B
             WHERE
                 A.approved='Y' AND
                 %s LIKE '%s' AND
                 A.id = B.id AND
                 A.id >= %s""" % (table_name, table_name, header,
                                  strutil.format_wildcards_sql(pattern),
                                  start_id)
     if end_id != 'ggg':
         stmt = "%s AND A.id <= %s" % (stmt, end_id)
     num_rows = self.cursor.execute(stmt)
     if num_rows == 0:
         return None
     result = list(self.cursor.fetchall())
     hdrs = []
     for row in result:
         if header.upper() == 'SUBJECT':
             hdrs.append('%s %s' % (row[0], row[4].strip()))
         elif header.upper() == 'FROM':
             # XXX: totally broken with empty values for the email address
             hdrs.append('%s %s <%s>' %
                         (row[0], row[2].strip(), row[3].strip()))
         elif header.upper() == 'DATE':
             hdrs.append(
                 '%s %s' %
                 (row[0],
                  strutil.get_formatted_time(time.localtime(result[5]))))
         elif header.upper() == 'MESSAGE-ID':
             hdrs.append('%s <%s@%s>' % (row[0], row[0], group_name))
         elif (header.upper() == 'REFERENCES') and (row[1] != 0):
             hdrs.append('%s <%s@%s>' % (row[0], row[1], group_name))
         elif header.upper() == 'BYTES':
             hdrs.append('%s %s' % (row[0], len(row[6])))
         elif header.upper() == 'LINES':
             hdrs.append('%s %s' % (row[0], len(row[6].split('\n'))))
         elif header.upper() == 'XREF':
             hdrs.append(
                 '%s %s %s:%s' %
                 (row[0], settings.nntp_hostname, group_name, row[0]))
     if len(hdrs) == 0:
         return ""
     else:
         return "\r\n".join(hdrs)
Beispiel #2
0
 def get_XPAT(self, group_name, header, pattern, start_id, end_id='ggg'):
     # XXX: need to actually check for the header values being passed as
     # XXX: not all header names map to column names on the tables
     table_name = self.get_table_name(group_name)
     stmt = """
             SELECT
                 A.id,
                 parent,
                 author,
                 email,
                 subject,
                 DATE_PART('epoch', datestamp) AS datestamp,
                 B.body
             FROM
                 %s A, 
                 %s_bodies B
             WHERE
                 A.approved='Y' AND
                 %s LIKE '%s' AND
                 A.id = B.id AND
                 A.id >= %s""" % (table_name, table_name, header, strutil.format_wildcards_sql(pattern), start_id)
     if end_id != 'ggg':
         stmt = "%s AND A.id <= %s" % (stmt, end_id)
     num_rows = self.cursor.execute(stmt)
     if num_rows == 0:
         return None
     result = list(self.cursor.fetchall())
     hdrs = []
     for row in result:
         if header.upper() == 'SUBJECT':
             hdrs.append('%s %s' % (row[0], row[4].strip()))
         elif header.upper() == 'FROM':
             # XXX: totally broken with empty values for the email address
             hdrs.append('%s %s <%s>' % (row[0], row[2].strip(), row[3].strip()))
         elif header.upper() == 'DATE':
             hdrs.append('%s %s' % (row[0], strutil.get_formatted_time(time.localtime(result[5]))))
         elif header.upper() == 'MESSAGE-ID':
             hdrs.append('%s <%s@%s>' % (row[0], row[0], group_name))
         elif (header.upper() == 'REFERENCES') and (row[1] != 0):
             hdrs.append('%s <%s@%s>' % (row[0], row[1], group_name))
         elif header.upper() == 'BYTES':
             hdrs.append('%s %s' % (row[0], len(row[6])))
         elif header.upper() == 'LINES':
             hdrs.append('%s %s' % (row[0], len(row[6].split('\n'))))
         elif header.upper() == 'XREF':
             hdrs.append('%s %s %s:%s' % (row[0], settings.nntp_hostname, group_name, row[0]))
     if len(hdrs) == 0:
         return ""
     else:
         return "\r\n".join(hdrs)
Beispiel #3
0
 def get_XGTITLE(self, pattern=None):
     stmt = """
             SELECT
                 nntp_group_name,
                 description
             FROM
                 forums
             WHERE
                 LENGTH(nntp_group_name) > 0"""
     if pattern != None:
         stmt = stmt + """ AND
                 nntp_group_name LIKE '%s'""" % (strutil.format_wildcards_sql(pattern))
     stmt = stmt + """
             ORDER BY
                 nntp_group_name ASC"""
     self.cursor.execute(stmt)
     result = list(self.cursor.fetchall())
     return "\r\n".join(["%s %s" % (k, v) for k, v in result])
Beispiel #4
0
 def get_XGTITLE(self, pattern=None):
     stmt = """
             SELECT
                 nntp_group_name,
                 description
             FROM
                 forums
             WHERE
                 LENGTH(nntp_group_name) > 0"""
     if pattern != None:
         stmt = stmt + """ AND
                 nntp_group_name LIKE '%s'""" % (
             strutil.format_wildcards_sql(pattern))
     stmt = stmt + """
             ORDER BY
                 nntp_group_name ASC"""
     self.cursor.execute(stmt)
     result = list(self.cursor.fetchall())
     return "\r\n".join(["%s %s" % (k, v) for k, v in result])