Пример #1
0
    def connect_and_search(self, credentials):

        self.stLog.emit('Connecting...', 0, False)

        try:
            http = httplib2.Http()
            # Authorize the httplib2.Http object with our credentials
            http = credentials.authorize(http)
            # Build the Gmail service from discovery
            self.gmApi = build('gmail', 'v1', http=http)

            profile = gm.get_user_profile(self.gmApi, self.userId)
            self.emailAddress = profile['emailAddress']

            labels = gm.list_labels(self.gmApi, self.userId)
            labelNameIDDict = dict([(label['name'], label['id']) for label in labels])

            if 'Defter' in labelNameIDDict.keys():
                defterLabelID = labelNameIDDict['Defter']
            else:
                defterLabel = gm.create_label(self.gmApi, self.userId, gm.make_label('Defter'))
                defterLabelID = defterLabel['id']

            # self.stLog.emit('Succesfully connected ...', 0, False)
            self.stConnectedToServer.emit(self.emailAddress)
            self.stLog.emit('Getting files please wait ...', 0, False)
            labelIdsNamesToFetchDict = {labelNameIDDict[labelFullName]: labelFullName for labelFullName in labelNameIDDict.keys() if labelFullName.startswith('Defter/')}
            labelIdsNamesToFetchDict[defterLabelID] = 'Defter'

            self.stMessageIdListsRetrieved.emit(labelIdsNamesToFetchDict)
            self.stFinished.emit()

        # except errors.HttpError, error:
        except Exception as e:
            # print 'An error occurred: %s' % error
            self.stLog.emit(("!!!  LOGIN FAILED  !!! {}".format(e)), 3, False)
            # self.stSetConnectButtonEnabled.emit(True)
            self.stFailed.emit()
            self.stFinished.emit()
Пример #2
0
    def create_folder(self, labelName, labelFullName, parent):

        newLabel = gm.create_label(self.gmApi, self.userId, gm.make_label(labelFullName))
        labelId = newLabel['id']
        self.stFolderCreated.emit(labelId, labelName, labelFullName, parent)