Example #1
0
    def handle_request(self, target=None, fields=None):
        result = self.validate_form()

        if not result:
            return

        title, workflow, archive, mailto, managers = result
        private_archives = "private_list" in self.request.form
        sync_project_membership = "sync_project_membership" in self.request.form

        list = self.context

        list.setTitle(title)
        list.setDescription(unicode(self.request.form.get('description',''), 'utf-8'))

        old_workflow_type = list.list_type
        new_workflow_type = workflow_to_mlist_type(workflow)
            
        notify(ListTypeChanged(list,
                               old_workflow_type.list_marker,
                               new_workflow_type.list_marker))


        list.archived = archive

        list.private_archives = private_archives
        if sync_project_membership:
            if not ISyncWithProjectMembership.providedBy(list):
                alsoProvides(list, ISyncWithProjectMembership)
        else:
            if ISyncWithProjectMembership.providedBy(list):
                noLongerProvides(list, ISyncWithProjectMembership)

        list.managers = tuple(managers)
        self._assign_local_roles_to_managers()
        list.reindexObject()
        # we need to manually commit the transaction here because we are about
        # to throw a Redirect exception which would abort the transaction
        transaction.commit()

        self.template = None

        s_message = _(u'list_preferences_updated',
                      u'Your changes have been saved.')
        
        self.add_status_message(s_message)
        # we need to raise a redirect here since permissions may have
        # been revoked for this view if the logged in user has removed
        # himself from the managers list
        raise Redirect('%s/summary' % list.absolute_url())
Example #2
0
def add_or_remove_membership(mship, remove=False):

    mem_id = mship.getId()
    team = mship.aq_inner.aq_parent
    proj_id = team.getId()
    portal = getToolByName(mship, 'portal_url').getPortalObject()
    listencontainer = portal.projects[proj_id].lists

    mlists = []

    for mlist in listencontainer.objectValues(spec='OpenMailingList'):
        if ISyncWithProjectMembership.providedBy(mlist):
            mlists.append(mlist)
           
    if not mlists:
        # no autosync mailing lists; silently fail
        return

    for ml in mlists:
        memlist = IWriteMembershipList(ml)

        if remove:
            memlist.unsubscribe(mem_id)
        else:
            memlist.subscribe(mem_id)
Example #3
0
    def save_list_archives(self):
        self.status.progress_descr = _(u'Saving mailing lists')
        try:
            listfol = self.context['lists']
        except KeyError:
            logger.error("No lists subfolder on %s" % self.context.getId())
            return

        real_site = getSite()
        for mlistid, mlist in listfol.objectItems(): # XXX filter more?
            logger.info("exporting %s" % mlistid)
            setSite(mlist)  # Needed to get the export adapter.
            mlistid = badchars.sub('_', mlistid)
            # Cargo-culted from listen/browser/import_export.py
            em = getAdapter(mlist, IMailingListMessageExport, name='mbox')
            # Nooo don't do it all in memory, we have seen some huge archives.
            #file_data = em.export_messages() or ''
            #self.zipfile.writestr('%s/lists/%s.mbox' % (self.context_dirname, mlistid),
            #                     file_data)
            tmpfd, tmpname = em.export_messages_to_tempfile()
            self.zipfile.write(tmpname,
                               '%s/lists/%s/archive.mbox' % (self.context_dirname, mlistid))
            os.unlink(tmpname)
            del(tmpfd)

            # Now the list subscribers.
            logger.info("exporting subscribers.csv for %s" % mlistid)
            es = getAdapter(mlist, IMailingListSubscriberExport, name='csv')
            file_data = es.export_subscribers(
                include_allowed_senders=True) or ''
            csv_path = '%s/lists/%s/subscribers.csv' % (self.context_dirname, mlistid)
            self.zipfile.writestr(csv_path, file_data)

            # Now the metadata and preferences.
            logger.info("exporting settings.ini for %s" % mlistid)
            list_info = {
                'id': mlist.getId(),
                'type': mlist_type_to_workflow(mlist),
                'mailto': mlist.mailto,
                'managers': mlist.managers,
                'archive_setting': mlist_archive_policy(mlist),
                'title': mlist.Title(),
                'description': mlist.Description(),
                'creation_date': mlist.CreationDate(),
                'creator': mlist.Creator(),
                'sync_with_project': ISyncWithProjectMembership.providedBy(mlist),
                'context': self.context.getId(),
                'private_archives': mlist.private_archives,
                }
            conf_path = '%s/lists/%s/settings.ini' % (self.context_dirname, mlistid)
            self.zipfile.writestr(conf_path, mlist_conf(list_info))

            setSite(real_site)
            logger.info("finished %s" % mlistid)
Example #4
0
 def sync_project_membership(self):
     return ISyncWithProjectMembership.providedBy(self)
    lists_folder = IListenContainer(IListenFeatureletInstalled(portal).lists)
    for mlist in lists_folder.objectValues(spec='OpenMailingList'):
        # what a silly API :-(
        notify(ListTypeChanged(mlist,
                               mlist.list_type.list_marker,
                               PostModerated.list_marker))
            
elif sys.argv[1] == 'remove':
    IFeatureletSupporter(portal).removeFeaturelet('listen')

elif sys.argv[1] == 'sync':
    lists_folder = IListenContainer(IListenFeatureletInstalled(portal).lists)

    mlists = []
    for mlist in lists_folder.objectValues(spec='OpenMailingList'):
        if ISyncWithProjectMembership.providedBy(mlist):
            mlists.append(mlist)

    site_users = getToolByName(portal, 'membrane_tool'
                               ).unrestrictedSearchResults(review_state='public')

    for user in site_users:
        for mlist in mlists:
            IWriteMembershipList(mlist).subscribe(user.getId)

else:
    print __doc__

after = IFeatureletSupporter(portal).getInstalledFeatureletIds()

import transaction
Example #6
0
    def save_list_archives(self):
        self.status.progress_descr = _(u'Saving mailing lists')
        try:
            listfol = self.context['lists']
        except KeyError:
            logger.error("No lists subfolder on %s" % self.context.getId())
            return

        real_site = getSite()
        for mlistid, mlist in listfol.objectItems(): # XXX filter more?
            logger.info("exporting %s" % mlistid)
            setSite(mlist)  # Needed to get the export adapter.
            mlistid = badchars.sub('_', mlistid)
            # Cargo-culted from listen/browser/import_export.py
            em = getAdapter(mlist, IMailingListMessageExport, name='mbox')
            # Nooo don't do it all in memory, we have seen some huge archives.
            #file_data = em.export_messages() or ''
            #self.zipfile.writestr('%s/lists/%s.mbox' % (self.context_dirname, mlistid),
            #                     file_data)
            tmpfd, tmpname = em.export_messages_to_tempfile()
            self.zipfile.write(tmpname,
                               '%s/lists/%s/archive.mbox' % (self.context_dirname, mlistid))
            os.unlink(tmpname)
            del(tmpfd)

            # Now the list subscribers.
            logger.info("exporting subscribers.csv for %s" % mlistid)
            es = getAdapter(mlist, IMailingListSubscriberExport, name='csv')
            file_data = es.export_subscribers(
                include_allowed_senders=True) or ''
            csv_path = '%s/lists/%s/subscribers.csv' % (self.context_dirname, mlistid)
            self.zipfile.writestr(csv_path, file_data)

            # And the pending subscriptions, unsubscriptions, and posts.
            from zope.annotation import IAnnotations
            import simplejson as json
            annot = IAnnotations(mlist).get('listen', {})

            this_annot = annot.get("pending_a_s_mod_email", {})
            this_annot_json = {}
            for mem_email in this_annot:
                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": this_annot[mem_email].get("user_name"),
                    }
            self.zipfile.writestr(
                '%s/lists/%s/pending_a_s_mod_email.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))

            this_annot = annot.get("a_s_pending_sub_email", {})
            this_annot_json = {}
            for mem_email in this_annot:
                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": this_annot[mem_email].get("user_name"),
                    }
            self.zipfile.writestr(
                '%s/lists/%s/a_s_pending_sub_email.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))

            this_annot = annot.get("pending_sub_email", {})
            this_annot_json = {}
            for mem_email in this_annot:
                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": this_annot[mem_email].get("user_name"),
                    }
            self.zipfile.writestr(
                '%s/lists/%s/pending_sub_email.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))

            this_annot = annot.get("pending_sub_mod_email", {})
            this_annot_json = {}
            for mem_email in this_annot:
                user_name = this_annot[mem_email].get("user_name")
                if isinstance(user_name, str):
                    try:
                        user_name = user_name.decode("utf8")
                    except UnicodeDecodeError:
                        user_name = user_name.decode("ISO-8859-1")
                if user_name:
                    user_name = user_name.encode("utf8")
                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": user_name,
                    }
            self.zipfile.writestr(
                '%s/lists/%s/pending_sub_mod_email.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))

            this_annot = annot.get("pending_unsub_email", {})
            this_annot_json = {}
            for mem_email in this_annot:
                user_name = this_annot[mem_email].get("user_name")
                if isinstance(user_name, str):
                    try:
                        user_name = user_name.decode("utf8")
                    except UnicodeDecodeError:
                        user_name = user_name.decode("ISO-8859-1")
                if user_name:
                    user_name = user_name.encode("utf8")
                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": user_name,
                    }
            self.zipfile.writestr(
                '%s/lists/%s/pending_unsub_email.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))
                        
            this_annot = annot.get("pending_mod_post", {})
            this_annot_json = {}
            for mem_email in this_annot:
                user_name = this_annot[mem_email].get("user_name")
                if isinstance(user_name, str):
                    try:
                        user_name = user_name.decode("utf8")
                    except UnicodeDecodeError:
                        user_name = user_name.decode("ISO-8859-1")
                if user_name:
                    user_name = user_name.encode("utf8")

                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": user_name,
                    "post": {},
                    }
                posts = this_annot[mem_email].get("post")
                for post_id in posts:
                    body = posts[post_id]['body']
                    header = posts[post_id]['header']
                    try:
                        body = body.decode("utf8").encode("utf8")
                    except UnicodeDecodeError:
                        try:
                            body = body.decode("ISO-8859-1").encode("utf8")
                        except UnicodeDecodeError:
                            body = body.decode("ascii").encode("utf8")
                    for header_name in header:
                        if header_name in header:
                            val = header[header_name]
                            try:
                                val = val.decode("utf8").encode("utf8")
                            except UnicodeDecodeError:
                                val = val.decode("ISO-8859-1").encode("utf8")
                            header[header_name] = val
                    this_annot_json[mem_email]['post'][post_id] = {
                        'header': header,
                        'body': body,
                        'postid': posts[post_id]['postid'],
                        }
            
            self.zipfile.writestr(
                '%s/lists/%s/pending_mod_post.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))

            this_annot = annot.get("pending_pmod_post", {})
            this_annot_json = {}
            for mem_email in this_annot:
                user_name = this_annot[mem_email].get("user_name")
                if isinstance(user_name, str):
                    try:
                        user_name = user_name.decode("utf8")
                    except UnicodeDecodeError:
                        user_name = user_name.decode("ISO-8859-1")
                if user_name:
                    user_name = user_name.encode("utf8")

                this_annot_json[mem_email] = {
                    "pin": this_annot[mem_email].get("pin"),
                    "time": this_annot[mem_email].get("time"),
                    "subscriber": this_annot[mem_email].get("subscriber"),
                    "user_name": user_name,
                    "post": {},
                    }
                posts = this_annot[mem_email].get("post")
                for post_id in posts:
                    body = posts[post_id]['body']
                    header = posts[post_id]['header']
                    try:
                        body = body.decode("utf8").encode("utf8")
                    except UnicodeDecodeError:
                        try:
                            body = body.decode("ISO-8859-1").encode("utf8")
                        except UnicodeDecodeError:
                            body = body.decode("ascii").encode("utf8")
                    for header_name in header:
                        if header_name in header:
                            val = header[header_name]
                            try:
                                val = val.decode("utf8").encode("utf8")
                            except UnicodeDecodeError:
                                val = val.decode("ISO-8859-1").encode("utf8")
                            header[header_name] = val
                    this_annot_json[mem_email]['post'][post_id] = {
                        'header': header,
                        'body': body,
                        'postid': posts[post_id]['postid'],
                        }

            self.zipfile.writestr(
                '%s/lists/%s/pending_pmod_post.json' % (self.context_dirname, mlistid),
                json.dumps(this_annot_json))
                        
            # Now the metadata and preferences.
            logger.info("exporting settings.ini for %s" % mlistid)
            list_info = {
                'id': mlist.getId(),
                'type': mlist_type_to_workflow(mlist),
                'mailto': mlist.mailto,
                'managers': mlist.managers,
                'archive_setting': mlist_archive_policy(mlist),
                'title': mlist.Title(),
                'description': mlist.Description(),
                'creation_date': str(mlist.created()),
                'modification_date': str(mlist.modified()),
                'creator': mlist.Creator(),
                'sync_with_project': ISyncWithProjectMembership.providedBy(mlist),
                'context': self.context.getId(),
                'private_archives': mlist.private_archives,
                }
            conf_path = '%s/lists/%s/settings.ini' % (self.context_dirname, mlistid)
            self.zipfile.writestr(conf_path, mlist_conf(list_info))

            setSite(real_site)
            logger.info("finished %s" % mlistid)