예제 #1
0
 def execute(self, request):
     if type(request) is InvalidRequestObject:
         return res.ResponseFailure.build_from_invalid_request_object(
             request)
     try:
         imap_client = ImapClient.connect(request.fields.get('conn'))
     except Exception as e:
         return res.ResponseFailure.build_system_error(
             f"{e.__class__.__name__}: {e}")
     return res.ResponseSuccess(imap_client)
예제 #2
0
 def execute(self, request):
     if type(request) is InvalidRequestObject:
         return res.ResponseFailure.build_from_invalid_request_object(
             request)
     try:
         mailbox = request.fields.get('name')
         result = self.imap_client.new_mb(mailbox)
     except Exception as e:
         return res.ResponseFailure.build_system_error(
             f"{e.__class__.__name__}: {e}")
     return res.ResponseSuccess(result)
예제 #3
0
 def execute(self, request):
     if type(request) is InvalidRequestObject:
         return res.ResponseFailure.build_from_invalid_request_object(
             request)
     try:
         self.imap_client.close()
     except Exception as e:
         # TODO: add key error handeling (.from_dict method),
         return res.ResponseFailure.build_system_error(
             f"{e.__class__.__name__}: {e}")
     return res.ResponseSuccess()
예제 #4
0
    def execute(self, request):
        if type(request) is InvalidRequestObject:
            return res.ResponseFailure.build_from_invalid_request_object(
                request)
        try:
            # mailbox is the destination. the email will be objects in the db, so
            # wont have a mailbox source as such.
            mailbox = request.fields.get('name')
            UIDs = request.fields.get('UIDs')

            result = self.imap_client.move_to(mailbox, UIDs)
        except Exception as e:
            return res.ResponseFailure.build_system_error(
                f"{e.__class__.__name__}: {e}")
        return res.ResponseSuccess(result)
예제 #5
0
 def execute(self, request):
     """
     executes a fetch command on the imap_client
     :param request: emailclean.requests.ImapReqObject
     :return: list of EMail objects (emailclean.domain.email.Email)
     """
     email_list = []
     if type(request) is InvalidRequestObject:
         return res.ResponseFailure.build_from_invalid_request_object(
             request)
     try:
         msg_list = self.imap_client.fetch(request.fields.get('name'))
     except Exception as e:
         # TODO: add key error handeling (.from_dict method),
         return res.ResponseFailure.build_system_error(
             f"{e.__class__.__name__}: {e}")
     return res.ResponseSuccess(msg_list)
예제 #6
0
def test_response_success_has_type_and_value(response_value):
    response = res.ResponseSuccess(response_value)

    assert response.type == res.ResponseSuccess.SUCCESS
    assert response.value == response_value
예제 #7
0
def test_response_success_is_true(response_value):
    assert bool(res.ResponseSuccess(response_value)) is True