@@ -594,6 +594,8 @@ class GetEmailParams(Params):
594594class GetEmailOutput (ActionOutput ):
595595 # Make all fields optional since not all emails have all headers
596596 # Using Pydantic Field with default=None for optional fields
597+ message : str | None = None
598+ container_id : int | None = None
597599 ARC_Authentication_Results : str | None = PydanticField (
598600 None , alias = "ARC-Authentication-Results"
599601 )
@@ -713,13 +715,36 @@ def get_email(params: GetEmailParams, soar: SOARClient, asset: Asset) -> GetEmai
713715 if params .id :
714716 helper ._connect_to_server ()
715717 email_data , _data_time_info = helper ._get_email_data (
716- params .id , params .folder if params .folder else asset .folder
718+ params .id , params .folder if params .folder else asset .folder , is_diff = True
717719 )
718720 mail = email .message_from_string (email_data )
719721
722+ # Handle ingestion if requested
723+ container_id = None
724+ if params .ingest_email :
725+ # Parse and create container/artifacts
726+ for obj in helper ._parse_and_create_artifacts (
727+ params .id , email_data , _data_time_info , asset
728+ ):
729+ if isinstance (obj , Container ):
730+ # Save the container and get its ID
731+ result = soar .save_container (obj )
732+ container_id = result .get ("id" )
733+ elif isinstance (obj , Artifact ):
734+ # Save the artifact
735+ if container_id :
736+ obj .container_id = container_id
737+ soar .save_artifact (obj )
738+
739+ message = f"Email ingested with container ID: { container_id } "
740+ else :
741+ message = "Email not ingested."
742+
720743 # Get mail headers
721744 headers = mail .__dict__ .get ("_headers" , [])
722- ret_val = {}
745+ ret_val = {"message" : message }
746+ if container_id :
747+ ret_val ["container_id" ] = container_id
723748 for header in headers :
724749 try :
725750 ret_val [header [0 ]] = str (make_header (decode_header (header [1 ])))
@@ -731,8 +756,28 @@ def get_email(params: GetEmailParams, soar: SOARClient, asset: Asset) -> GetEmai
731756
732757 return GetEmailOutput (** ret_val )
733758
734- # Container ID handling would go here
735- raise NotImplementedError ("Container ID handling not yet implemented" )
759+ # Handle container_id parameter - fetch email from existing container
760+ if params .container_id :
761+ # Get container data from SOAR
762+ container = soar .get_container (params .container_id )
763+ if not container :
764+ raise ValueError (f"Container with ID { params .container_id } not found" )
765+
766+ # Get artifacts from the container
767+ soar .get_container_artifacts (params .container_id )
768+
769+ # Extract email headers from artifacts/container data
770+ ret_val = {"message" : "Email retrieved from container." }
771+
772+ # Get container data which should have email info
773+ if container .get ("data" ):
774+ email_data = container ["data" ]
775+ if isinstance (email_data , dict ):
776+ ret_val .update (email_data )
777+
778+ return GetEmailOutput (** ret_val )
779+
780+ raise ValueError ("Please specify either id or container_id to get the email" )
736781
737782
738783if __name__ == "__main__" :
0 commit comments