Esempio n. 1
0
    def setUp(self):
        self.fileWrapper = DummyFileWrapper()

        fileinfo = {
            'dirname': 'post_title',
            'filename': 'real_filename',
            'filepath': 'filepath',
            'filesize': 123456,
            'parts': 2,
        }

        # setup enviroment variable
        self.conf = {}
        self.conf['server'] = {'hostname': 'test.Host'}
        self.conf['posting'] = {'from': 'testFrom@Account'}
        self.newsgroup = 'test.Newsgroup'
        subject = 'testSubject [1/3] - "testFile" yEnc (1/1)'
        partnum = fileinfo['parts']

        self.art = Article(self.fileWrapper, 0, 3, fileinfo, subject, partnum)

        self.art.headers['From'] = self.conf['posting']['from']
        self.art.headers['Newsgroups'] = self.newsgroup
        self.art.headers['Subject'] = subject  #% (partnum)
        self.art.headers['Message-ID'] = '<%.5f.%d@%s>' % (
            time.time(), partnum, self.conf['server']['hostname'])
        self.art.headers['X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % \
                ('0.0.1', 'yenc.yEncMode()')
Esempio n. 2
0
 def setUp(self):
     self.fileWrapper = DummyFileWrapper()
     
     fileinfo = {
         'dirname': 'post_title',
         'filename': 'real_filename',
         'filepath': 'filepath',
         'filesize': 123456,
         'parts': 2,
     }
     
     # setup enviroment variable
     self.conf = {}
     self.conf['server'] = {'hostname':'test.Host'}
     self.conf['posting'] = {'from' : 'testFrom@Account'}
     self.newsgroup = 'test.Newsgroup'
     subject = 'testSubject [1/3] - "testFile" yEnc (1/1)'
     partnum = fileinfo['parts']
     
     self.art = Article(self.fileWrapper, 0, 3, fileinfo, subject, partnum)
     
     self.art.headers['From'] = self.conf['posting']['from']
     self.art.headers['Newsgroups'] = self.newsgroup
     self.art.headers['Subject'] = subject #% (partnum)
     self.art.headers['Message-ID'] = '<%.5f.%d@%s>' % (time.time(), partnum, self.conf['server']['hostname'])
     self.art.headers['X-Newsposter'] = 'newsmangler %s (%s) - https://github.com/madcowfred/newsmangler\r\n' % \
             ('0.0.1', 'yenc.yEncMode()')
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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
Esempio n. 6
0
    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