Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Feature Forums
  3. - Uncategorised posts -
  4. Rename EML files With Message Subject Line

Rename EML files With Message Subject Line

Scheduled Pinned Locked Moved - Uncategorised posts -
helptutorialquestion
5 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14693814
    wrote on last edited by
    #1

    I am not sure this is the place to ask. I found this site when a Google search return a page for EMLReader. My issue is with our mail archive/journaling. When we retrieve messages they are downloaded with file names like: 00db2d52a8081ad5e1e8e8da3fd020c3bc06e12a7b87798056be9e45f68dba8c.eml When they are uploaded the names contain information like subject, To and From. Is there a way to grab information from the EML file and rename it with the subject line for example?

    Richard DeemingR 1 Reply Last reply
    0
    • M Member_14693814

      I am not sure this is the place to ask. I found this site when a Google search return a page for EMLReader. My issue is with our mail archive/journaling. When we retrieve messages they are downloaded with file names like: 00db2d52a8081ad5e1e8e8da3fd020c3bc06e12a7b87798056be9e45f68dba8c.eml When they are uploaded the names contain information like subject, To and From. Is there a way to grab information from the EML file and rename it with the subject line for example?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You should be able to use MimeKit[^] to parse the file. If you just want the subject, you don't even need to load the whole file:

      public static string GetMessageSubject(string fileName)
      {
      var headers = MimeKit.HeaderList.Load(fileName);
      return headers[MimeKit.HeaderId.Subject];
      }

      NB: Be aware that the message subject could contain characters which are not valid in a filename. It could also be longer than the maximum allowable filename, or make the file's path longer than the maximum allowable file path.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        You should be able to use MimeKit[^] to parse the file. If you just want the subject, you don't even need to load the whole file:

        public static string GetMessageSubject(string fileName)
        {
        var headers = MimeKit.HeaderList.Load(fileName);
        return headers[MimeKit.HeaderId.Subject];
        }

        NB: Be aware that the message subject could contain characters which are not valid in a filename. It could also be longer than the maximum allowable filename, or make the file's path longer than the maximum allowable file path.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Member_14693814
        wrote on last edited by
        #3

        Thank you for your reply. More specifically I am looking for something that would rename all the files within a folder. We have folders that can contain over 100,000 files. Unfortunately I am not an expert at scripting so I am looking for a complete script. If I wanted to add To and From in the name would it be as simple as adding another line like: return headers[MimeKit.HeaderId.To];

        Richard DeemingR 1 Reply Last reply
        0
        • M Member_14693814

          Thank you for your reply. More specifically I am looking for something that would rename all the files within a folder. We have folders that can contain over 100,000 files. Unfortunately I am not an expert at scripting so I am looking for a complete script. If I wanted to add To and From in the name would it be as simple as adding another line like: return headers[MimeKit.HeaderId.To];

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Yes, headers[MimeKit.HeaderId.To] will return the list of addresses in the "To" field, and headers[MimeKit.HeaderId.From] will return the list of addresses in the "From" field. There could potentially be multiple addresses in both fields. And the same caveat about invalid characters and filename/path length limitations applies.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          N 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Yes, headers[MimeKit.HeaderId.To] will return the list of addresses in the "To" field, and headers[MimeKit.HeaderId.From] will return the list of addresses in the "From" field. There could potentially be multiple addresses in both fields. And the same caveat about invalid characters and filename/path length limitations applies.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            N Offline
            N Offline
            Nilo Wilson
            wrote on last edited by
            #5

            I didn't even know about that. Thanks for the clarification.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups