def build_article(self, fileinfo, subject, partnum, begin, end): # Read the chunk of data from the file #f = self._files.get(fileinfo['filepath'], None) #if f is None: # self._files[fileinfo['filepath']] = f = open(fileinfo['filepath'], 'rb') #begin = f.tell() #data = f.read(self.conf['posting']['article_size']) #end = f.tell() # If that was the last part, close the file and throw it away #if partnum == fileinfo['parts']: # self._files[fileinfo['filepath']].close() # del self._files[fileinfo['filepath']] # Make a new article object and set headers art = Article(begin, end, fileinfo, subject, partnum) art.headers['From'] = self.conf['posting']['from'] art.headers['Newsgroups'] = self.newsgroup art.headers['Subject'] = subject % (partnum) art.headers['Message-ID'] = '<%.5f.%d@%s>' % (time.time(), partnum, self.conf['server']['virtualhost']) art.headers['X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % ( NM_VERSION, yenc.yEncMode()) self._articles.append(art)
def build_article(self, fileinfo, subject, partnum, begin, end): # Read the chunk of data from the file #f = self._files.get(fileinfo['filepath'], None) #if f is None: # self._files[fileinfo['filepath']] = f = open(fileinfo['filepath'], 'rb') #begin = f.tell() #data = f.read(self.conf['posting']['article_size']) #end = f.tell() # If that was the last part, close the file and throw it away #if partnum == fileinfo['parts']: # self._files[fileinfo['filepath']].close() # del self._files[fileinfo['filepath']] # Make a new article object and set headers art = Article(begin, end, fileinfo, subject, partnum) art.headers['From'] = self.conf['posting']['from'] art.headers['Newsgroups'] = self.newsgroup art.headers['Subject'] = subject % (partnum) art.headers['Message-ID'] = '<%.5f.%d@%s>' % ( time.time(), partnum, self.conf['server']['hostname']) art.headers[ 'X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % ( NM_VERSION, yenc.yEncMode()) self._articles.append(art)
def __init__(self, conf, debug=False): self.conf = conf self._conns = [] self._idle = [] # Create our logger self.logger = logging.getLogger('mangler') handler = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s [%(levelname)s] %(message)s') handler.setFormatter(formatter) self.logger.addHandler(handler) if debug: self.logger.setLevel(logging.DEBUG) else: self.logger.setLevel(logging.INFO) # Create a poll object for async bits to use. If the user doesn't have # poll, we're going to have to fake it. try: asyncore.poller = select.poll() self.logger.info('Using poll() for sockets') except AttributeError: from newsmangler.fakepoll import FakePoll asyncore.poller = FakePoll() self.logger.info('Using FakePoll() for sockets') self.conf['posting']['skip_filenames'] = self.conf['posting'].get( 'skip_filenames', '').split() self.ssl = self.conf['server'].get('ssl') if self.ssl: self.logger.info( "SSL enabled. Connections can take more time to be established." ) self._articles = [] self._files = {} self._msgids = {} self._current_dir = None self.newsgroup = None self.post_title = None # Some sort of useful logging junk about which yEncode we're using self.logger.info('Using %s module for yEnc', yenc.yEncMode())
def __init__(self, conf, debug=False): self.conf = conf self._conns = [] self._idle = [] # Create our logger self.logger = logging.getLogger('mangler') handler = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') handler.setFormatter(formatter) self.logger.addHandler(handler) if debug: self.logger.setLevel(logging.DEBUG) else: self.logger.setLevel(logging.INFO) # Create a poll object for async bits to use. If the user doesn't have # poll, we're going to have to fake it. try: asyncore.poller = select.poll() self.logger.info('Using poll() for sockets') except AttributeError: from newsmangler.fakepoll import FakePoll asyncore.poller = FakePoll() self.logger.info('Using FakePoll() for sockets') self.conf['posting']['skip_filenames'] = self.conf['posting'].get('skip_filenames', '').split() self.ssl = self.conf['server'].get('ssl') if self.ssl: self.logger.info("SSL enabled. Connections can take more time to be established.") self._articles = [] self._files = {} self._msgids = {} self._current_dir = None self.newsgroup = None self.post_title = None # Some sort of useful logging junk about which yEncode we're using self.logger.info('Using %s module for yEnc', yenc.yEncMode())
def _gal_files(self, post_title, files, basepath=''): article_size = self.conf['posting']['article_size'] goodfiles = [] for filename in files: filepath = os.path.abspath(os.path.join(basepath, filename)) # Skip non-files and empty files if not os.path.isfile(filepath): continue if filename in self.conf['posting']['skip_filenames'] or filename == '.newsmangler': continue filesize = os.path.getsize(filepath) if filesize == 0: continue goodfiles.append((filepath, filename, filesize)) goodfiles.sort() # Do stuff with files n = 1 for filepath, filename, filesize in goodfiles: parts, partial = divmod(filesize, article_size) if partial: parts += 1 self._files[filepath] = FileWrap(filepath, parts) # Build a subject real_filename = os.path.split(filename)[1] temp = '%%0%sd' % (len(str(len(files)))) filenum = temp % (n) temp = '%%0%sd' % (len(str(parts))) subject = '%s [%s/%d] - "%s" yEnc (%s/%d)' % ( post_title, filenum, len(goodfiles), real_filename, temp, parts ) # Apply a subject prefix if self.conf['posting']['subject_prefix']: subject = '%s %s' % (self.conf['posting']['subject_prefix'], subject) # Now make up our parts fileinfo = { 'dirname': post_title, 'filename': real_filename, 'filepath': filepath, 'filesize': filesize, 'parts': parts, } for i in range(parts): partnum = i + 1 begin = 0 + (i * article_size) end = min(filesize, partnum * article_size) # Build the article art = Article(self._files[filepath], begin, end, fileinfo, subject, partnum) art.headers['From'] = self.conf['posting']['from'] art.headers['Newsgroups'] = self.newsgroup art.headers['Subject'] = subject % (partnum) art.headers['Message-ID'] = '<%.5f.%d@%s>' % (time.time(), partnum, self.conf['server']['virtualhost']) art.headers['X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % ( NM_VERSION, yenc.yEncMode()) self._articles.append(art) n += 1
def _gal_files(self, post_title, files, basepath=''): article_size = self.conf['posting']['article_size'] goodfiles = [] for filename in files: filepath = os.path.abspath(os.path.join(basepath, filename)) # Skip non-files and empty files if not os.path.isfile(filepath): continue if filename in self.conf['posting'][ 'skip_filenames'] or filename == '.newsmangler': continue filesize = os.path.getsize(filepath) if filesize == 0: continue goodfiles.append((filepath, filename, filesize)) goodfiles.sort() # Do stuff with files n = 1 for filepath, filename, filesize in goodfiles: parts, partial = divmod(filesize, article_size) if partial: parts += 1 self._files[filepath] = FileWrap(filepath, parts) # Build a subject real_filename = os.path.split(filename)[1] temp = '%%0%sd' % (len(str(len(files)))) filenum = temp % (n) temp = '%%0%sd' % (len(str(parts))) subject = '%s [%s/%d] - "%s" yEnc (%s/%d)' % ( post_title, filenum, len(goodfiles), real_filename, temp, parts) # Apply a subject prefix if self.conf['posting']['subject_prefix']: subject = '%s %s' % (self.conf['posting']['subject_prefix'], subject) # Now make up our parts fileinfo = { 'dirname': post_title, 'filename': real_filename, 'filepath': filepath, 'filesize': filesize, 'parts': parts, } for i in range(parts): partnum = i + 1 begin = 0 + (i * article_size) end = min(filesize, partnum * article_size) # Build the article art = Article(self._files[filepath], begin, end, fileinfo, subject, partnum) art.headers['From'] = self.conf['posting']['from'] art.headers['Newsgroups'] = self.newsgroup art.headers['Subject'] = subject % (partnum) art.headers['Message-ID'] = '<%.5f.%d@%s>' % ( time.time(), partnum, self.conf['server']['hostname']) art.headers[ 'X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % ( NM_VERSION, yenc.yEncMode()) self._articles.append(art) n += 1