def email_inbox():
    """
        RESTful CRUD controller for the Email Inbox
        - all Inbound Email Messages are visible here

        @ToDo: Filter to those which have been unable to be automatically
               processed as being responses to Alerts
        @ToDo: Filter to those coming into the specific account used for
               Deployments
        @ToDo: Provide a mechanism (Action button?) to link a mail manually to
               an Alert
    """

    if not auth.s3_logged_in():
        session.error = T("Requires Login!")
        redirect(URL(c="default", f="user", args="login"))

    tablename = "msg_email"
    table = s3db.msg_email
    table.inbound.readable = False
    table.channel_id.readable = False
    table.to_address.readable = False

    from s3.s3query import FS
    s3.filter = (FS("response.id") == None) & \
                (FS("inbound") == True)

    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent
    crud_form = S3SQLCustomForm("date",
                                "subject",
                                "from_address",
                                "body",
                                S3SQLInlineComponent(
                                    "attachment",
                                    name = "document_id",
                                    label = T("Attachments"),
                                    fields = ["document_id",
                                              ],
                                    ),
                                )

    s3db.configure(tablename,
                   crud_form = crud_form,
                   editable = False,
                   insertable = False,
                   list_fields = ["id",
                                  "date",
                                  "from_address",
                                  "subject",
                                  "body",
                                  (T("Attachments"), "attachment.document_id"),
                                  ],
                   )

    # CRUD Strings
    s3.crud_strings[tablename] = Storage(
        title_list = T("View InBox"),
        title_update = T("Edit Message"),
        label_list_button = T("View InBox"),
        label_delete_button = T("Delete Message"),
        msg_record_modified = T("Message updated"),
        msg_record_deleted = T("Message deleted"),
        msg_list_empty = T("No Messages currently in InBox")
    )

    def prep(r):
        # Decode subject and sender fields
        decode = current.msg.decode_email
        if r.id:
            s3db.msg_attachment.document_id.label = ""
            if r.component and r.component.alias == "select":
                if not r.method:
                    r.method = "select"
                if r.method == "select":
                    r.custom_action = s3db.deploy_response_select_mission
            represent = lambda string: decode(string)
        elif not r.method and r.representation in ("html", "aadata"):
            # Use custom data table method
            r.method = "inbox"
            r.custom_action = s3db.deploy_Inbox()
            represent = lambda string: s3base.s3_datatable_truncate(decode(string))
        table = r.resource.table
        table.subject.represent = represent
        table.from_address.represent = represent
        return True
    s3.prep = prep

    def postp(r, output):
        if r.interactive and r.record and not r.component:
            # Custom CRUD button for linking the message to mission
            authorised = auth.s3_has_permission("create", "deploy_response")
            if authorised:
                s3.rfooter = s3base.S3CRUD.crud_button(
                                        T("Link to Mission"),
                                        _href=URL(f="email_inbox",
                                                  args=[r.id, "select"],
                                                  ),
                                        _class="action-btn link",
                                        )
        return output
    s3.postp = postp

    return s3_rest_controller("msg", "email")

# -----------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/controllers/deploy.py/email_inbox/original