api.v1.views package

api.v1.views package containing the views for the Eonvelope API version 1.

class api.v1.views.AccountViewSet(**kwargs)[source]

Bases: ModelViewSet, ToggleFavoriteMixin

Viewset for the core.models.Account.

Provides all actions.

BASENAME = 'account'
serializer_class

alias of AccountSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of AccountFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['mail_address', 'mail_host', 'mail_host_port', 'protocol', 'timeout', 'is_healthy', 'is_favorite', 'created', 'updated']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Fetches the queryset by filtering the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The account entries matching the request user.

URL_PATH_UPDATE_MAILBOXES = 'update-mailboxes'
URL_NAME_UPDATE_MAILBOXES = 'update-mailboxes'
update_mailboxes(request, pk=None)[source]

Action method updating the mailboxes in the account.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the account to scan for mailboxes. Defaults to None.

Return type:

Response

Returns:

A response containing the updated account data.

URL_PATH_ADD_DAEMONS = 'add-routines'
URL_NAME_ADD_DAEMONS = 'add-daemons'
add_daemons(request, pk=None)[source]

Action method updating the mailboxes in the account.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the account to scan for mailboxes. Defaults to None.

Return type:

Response

Returns:

A response containing the updated account data.

URL_PATH_TEST = 'test'
URL_NAME_TEST = 'test'
test(request, pk=None)[source]

Action method testing the account data.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the account to test. Defaults to None.

Return type:

Response

Returns:

A response containing the updated account data and the test result.

URL_PATH_DOWNLOAD = 'download'
URL_NAME_DOWNLOAD = 'download'
download(request, pk=None)[source]

Action method downloading the eml files of all emails in the account in a single file.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the account to download. Defaults to None.

Raises:
  • Http404 – If there are no mailboxes in the account.

  • ValidationError – If file_format is missing or unsupported.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the mailboxes in the requested format.

basename = None
create(request, *args, **kwargs)
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
update(request, *args, **kwargs)
class api.v1.views.AttachmentViewSet(**kwargs)[source]

Bases: ReadOnlyModelViewSet, DestroyModelMixin, ToggleFavoriteMixin

Viewset for the core.models.Attachment.

Provides every read-only and a destroy action.

BASENAME = 'attachment'
serializer_class

alias of BaseAttachmentSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of AttachmentFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['file_name', 'datasize', 'email__datetime', 'is_favorite', 'created', 'updated']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Filters the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The attachment entries matching the request user.

URL_PATH_DOWNLOAD = 'download'
URL_NAME_DOWNLOAD = 'download'
download(request, pk=None)[source]

Action method downloading the attachment.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to download. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_DOWNLOAD_BATCH = 'download'
URL_NAME_DOWNLOAD_BATCH = 'download-batch'
download_batch(request)[source]

Action method downloading a batch of attachments.

Parameters:

request (Request) – The request triggering the action.

Raises:
  • Http404 – If no downloadable attachment has been requested.

  • ValidationError – If id param is missing or in invalid format.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_THUMBNAIL = 'thumbnail'
URL_NAME_THUMBNAIL = 'thumbnail'
download_thumbnail(request, pk=None)[source]

Action method downloading the attachment thumbnail.

Returns the same filedata as ‘download’, but as inline.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to download. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_SHARE_TO_PAPERLESS = 'share/paperless'
URL_NAME_SHARE_TO_PAPERLESS = 'share-to-paperless'
share_to_paperless(request, pk=None)[source]

Action method sending the attachment to the users Paperless server.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to upload. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

Response

Returns:

A fileresponse containing the requested file.

URL_PATH_SHARE_TO_IMMICH = 'share/immich'
URL_NAME_SHARE_TO_IMMICH = 'share-to-immich'
share_to_immich(request, pk=None)[source]

Action method sending the attachment to the users Immich server.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to upload. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

Response

Returns:

A fileresponse containing the requested file.

basename = None
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
class api.v1.views.CorrespondentViewSet(**kwargs)[source]

Bases: ReadOnlyModelViewSet, UpdateModelMixin, DestroyModelMixin, ToggleFavoriteMixin

Viewset for the core.models.Correspondent.Correspondent.

Provides every read-only and a destroy action.

BASENAME = 'correspondent'
serializer_class

alias of CorrespondentSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of CorrespondentFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['email_name', 'email_address', 'is_favorite', 'created', 'updated']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Filters the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The correspondent entries matching the request user.

get_serializer_class()[source]

Sets the serializer for list requests to the simplified version.

Return type:

type[BaseSerializer]

URL_PATH_DOWNLOAD = 'download'
URL_NAME_DOWNLOAD = 'download'
download(request, pk=None)[source]

Action method downloading the correspondent.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the correspondent to download. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_DOWNLOAD_BATCH = 'download'
URL_NAME_DOWNLOAD_BATCH = 'download-batch'
download_batch(request)[source]

Action method downloading a batch of correspondents.

Parameters:

request (Request) – The request triggering the action.

Raises:
  • Http404 – If no downloadable correspondent has been requested.

  • ValidationError – If id param is missing or in invalid format.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_SHARE_TO_NEXTCLOUD = 'share/nextcloud'
URL_NAME_SHARE_TO_NEXTCLOUD = 'share-to-nextcloud'
share_to_nextcloud(request, pk=None)[source]

Action method sending the correspondent to the users Immich server.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the correspondent to upload. Defaults to None.

Return type:

Response

Returns:

A fileresponse containing the requested file.

basename = None
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
update(request, *args, **kwargs)
class api.v1.views.DaemonViewSet(**kwargs)[source]

Bases: ModelViewSet

Viewset for the core.models.Daemon.

Provides all CRUD actions.

Note

To update instances the user must specify format “json” with the request.

BASENAME = 'daemon'
serializer_class

alias of BaseDaemonSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of DaemonFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['fetching_criterion', 'interval__every', 'interval__period', 'celery_task__last_run_at', 'celery_task__total_run_count', 'is_healthy', 'mailbox__name', 'mailbox__account__mail_address', 'mailbox__account__mail_host', 'mailbox__account__protocol', 'created', 'updated']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Filters the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The daemon entries matching the request user.

URL_PATH_TEST = 'test'
URL_NAME_TEST = 'test'
test(request, pk=None)[source]

Action method testing the daemon data of the mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the daemon. Defaults to None.

Return type:

Response

Returns:

A response detailing the test result for the daemon.

URL_PATH_START = 'start'
URL_NAME_START = 'start'
start(request, pk=None)[source]

Action method starting the daemon for the mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the daemon. Defaults to None.

Return type:

Response

Returns:

A response detailing the start result of the daemon.

URL_PATH_STOP = 'stop'
URL_NAME_STOP = 'stop'
stop(request, pk=None)[source]

Action method stopping the daemon data of the mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the daemon. Defaults to None.

Return type:

Response

Returns:

A response detailing the stop result for the daemon.

basename = None
create(request, *args, **kwargs)
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
update(request, *args, **kwargs)
class api.v1.views.DatabaseStatsView(**kwargs)[source]

Bases: APIView

APIView for the statistics of the database.

NAME = 'stats'
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
serializer_class

alias of DatabaseStatsSerializer

get(request)[source]

Gets all the number of entries in the tables of the database.

Parameters:

request (Request) – The GET request to respond to.

Return type:

Response

Returns:

A dictionary with the count of the table entries.

class api.v1.views.EmailViewSet(**kwargs)[source]

Bases: ReadOnlyModelViewSet, DestroyModelMixin, ToggleFavoriteMixin

Viewset for the core.models.Email.Email.

Provides every read-only and a destroy action.

BASENAME = 'email'
serializer_class

alias of FullEmailSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of EmailFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['datetime', 'subject', 'datasize', 'is_favorite', 'created', 'updated', 'user_agent', 'language', 'content_language', 'importance', 'priority', 'precedence', 'x_priority', 'x_originated_client']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Filters the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The email entries matching the request user.

get_serializer_class()[source]

Sets the serializer for list requests to the simplified version.

Return type:

type[BaseSerializer]

URL_PATH_DOWNLOAD = 'download'
URL_NAME_DOWNLOAD = 'download'
download(request, pk=None)[source]

Action method downloading the eml file of the email.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to download. Defaults to None.

Raises:

Http404 – If the filepath is not in the database or it doesn’t exist.

Return type:

FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_DOWNLOAD_BATCH = 'download'
URL_NAME_DOWNLOAD_BATCH = 'download-batch'
download_batch(request)[source]

Action method downloading a batch of emails.

Todo

Validation and parsing of queryparams can probably be done more concisely with a serializer.

Parameters:

request (Request) – The request triggering the action.

Raises:
  • Http404 – If there are no emails in the mailbox.

  • ValidationError – If id or file_format param is missing or in invalid format or file_format is unsupported.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the emails in the requested format.

URL_PATH_THUMBNAIL = 'thumbnail'
URL_NAME_THUMBNAIL = 'thumbnail'
download_thumbnail(request, pk=None)[source]

Action method downloading the html version of the mail.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the email to download. Defaults to None.

Return type:

FileResponse

Returns:

A fileresponse containing the requested file.

URL_PATH_FULLCONVERSATION = 'full-conversation'
URL_NAME_FULLCONVERSATION = 'full-conversation'
conversation(request, pk=None)[source]

Action method getting the complete conversation a mail is part of.

The response data is paginated analogous to the list method.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the email to get the complete conversation it belongs to. Defaults to None.

Return type:

Response

Returns:

A response detailing the request status.

URL_PATH_RESTORE = 'restore'
URL_NAME_RESTORE = 'restore'
restore(request, pk=None)[source]

Action method restoring the email to its mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the email to get the complete conversation it belongs to. Defaults to None.

Return type:

Response

Returns:

A response detailing the request status.

URL_PATH_REPROCESS = 'reprocess'
URL_NAME_REPROCESS = 'reprocess'
reprocess(request, pk=None)[source]

Action method reprocessing the emails connections to other emails.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the email to reprocess. Defaults to None.

Return type:

Response

Returns:

A response detailing the request status.

basename = None
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
class api.v1.views.MailboxViewSet(**kwargs)[source]

Bases: ReadOnlyModelViewSet, UpdateModelMixin, DestroyModelMixin, ToggleFavoriteMixin

Viewset for the core.models.Mailbox.Mailbox.

Provides all but the create action.

BASENAME = 'mailbox'
serializer_class

alias of MailboxWithDaemonSerializer

filter_backends = [<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'rest_framework.filters.OrderingFilter'>]
filterset_class

alias of MailboxFilterSet

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
ordering_fields: Final[list[str]] = ['name', 'account__mail_address', 'account__mail_host', 'account__protocol', 'save_attachments', 'save_to_eml', 'is_favorite', 'is_healthy', 'created', 'updated']
ordering: Final[list[str]] = ['id']
get_queryset()[source]

Filters the data for entries connected to the request user.

Return type:

QuerySet

Returns:

The mailbox entries matching the request user.

URL_PATH_TEST = 'test'
URL_NAME_TEST = 'test'
test(request, pk=None)[source]

Action method testing the mailbox data.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the mailbox to test. Defaults to None.

Return type:

Response

Returns:

A response containing the updated mailbox data and the test result.

URL_PATH_FETCHING_OPTIONS = 'fetching-options'
URL_NAME_FETCHING_OPTIONS = 'fetching-options'
fetching_options(request, pk=None)[source]

Action method returning all fetching options for the mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – int: The private key of the mailbox. Defaults to None.

Return type:

Response

Returns:

A response detailing the request status.

URL_PATH_FETCH = 'fetch'
URL_NAME_FETCH = 'fetch'
fetch(request, pk=None)[source]

Action method fetching all mails from the mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the mailbox. Defaults to None.

Return type:

Response

Returns:

A response with the mailbox data.

URL_PATH_DOWNLOAD = 'download'
URL_NAME_DOWNLOAD = 'download'
download(request, pk=None)[source]

Action method downloading the eml files of all emails in the mailbox in a single file.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – The private key of the attachment to download. Defaults to None.

Raises:
  • Http404 – If there are no emails in the mailbox.

  • ValidationError – If file_format is missing or unsupported.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the emails in the requested format.

URL_PATH_DOWNLOAD_BATCH = 'download'
URL_NAME_DOWNLOAD_BATCH = 'download-batch'
download_batch(request)[source]

Action method downloading a batch of mailboxes.

Todo

Validation and parsing of queryparams can probably be done more concisely with a serializer.

Parameters:

request (Request) – The request triggering the action.

Raises:
  • Http404 – If there are no emails in the mailbox.

  • ValidationError – If id or file_format param is missing or in invalid format or file_format is unsupported.

Return type:

Response | FileResponse

Returns:

A fileresponse containing the mailboxes emails in the requested format.

URL_PATH_UPLOAD_MAILBOX = 'upload'
URL_NAME_UPLOAD_MAILBOX = 'upload'
upload_emails(request, pk=None)[source]

Action method allowing upload of a mailbox file and adding the contained mails to a mailbox.

Parameters:
  • request (Request) – The request triggering the action.

  • pk (int | None) – int: The private key of the mailbox to upload to. Defaults to None.

Return type:

Response

Returns:

A response detailing the request status.

basename = None
description = None
destroy(request, *args, **kwargs)
detail = None
list(request, *args, **kwargs)
name = None
retrieve(request, *args, **kwargs)
suffix = None
update(request, *args, **kwargs)
class api.v1.views.UserProfileView(**kwargs)[source]

Bases: RetrieveUpdateAPIView

View for retrieving and updating the users eonvelope.models.UserProfile.

NAME = 'profile'
serializer_class

alias of UserProfileSerializer

permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
get_object()[source]

Fetches the profile connected to the request user.

Return type:

UserProfile

Returns:

The UserProfile model of the request user.

retrieve(request, *args, **kwargs)
update(request, *args, **kwargs)

Submodules