scott-p of MagicLamp Enterprise Repo
3/2/2017 - 6:20 PM

This is used in getEMLDetailsandAttachment. Addresses filenames in .EML that span multiple lines. The ExtractContent calls this, this has be

This is used in getEMLDetailsandAttachment. Addresses filenames in .EML that span multiple lines. The ExtractContent calls this, this has been updated to address filenames that span multiple lines in the .EML file ingested by Datacap.

//This is used in getEMLDetailsandAttachment. The ExtractContent calls this, this has been updated to address filenames that span multiple lines in the .EML file ingested by Datacap.

private string GetFilename(TextReader reader, string line)
        {
            string filename;
            int filenameStart = line.IndexOf('"') + 1;
            int filenameend = line.IndexOf("\"", filenameStart);
            //Content-Disposition: attachment;
            //filename = "Order example 7 with quote number.pdf"; size = 85375;

            if (filenameend <= 0)
            {
                WriteLog("Couldn't find end of filename on first line, lets check subsequent lines");

                // Filename starts with first line all the way to end of first line
                filename = line.Substring(filenameStart);

                //Get the second line
                string otherHalf = reader.ReadLine();

                //Still havent found the end of the filename, loop through next lines
                if (!otherHalf.Contains('"'))
                {
                    //Haven't found the end of the filename yet, add this current piece to the filename.
                    filename = filename + otherHalf;

                    WriteLog("Didn't find end of filename on second line, look at each subsequent line until end found");

                    string foundEnd = "N";

                    do
                    {
                        // Next line
                        otherHalf = reader.ReadLine();

                        if (otherHalf.Contains('"'))
                        {
                            foundEnd = "Y";
                        }
                        else //Havent found last line yet, add current line to filename
                        {
                            filename = filename + otherHalf;
                        }

                    } while (foundEnd != "Y");

                    //Found the line with the end of the filename, trim the excess off the line
                    otherHalf = otherHalf.Substring(0, otherHalf.IndexOf('"'));
                }
                else
                {
                    otherHalf = otherHalf.Substring(0, otherHalf.IndexOf('"'));
                }  

                filename = filename + otherHalf;
                WriteLog("Filename from multiple lines: " + filename);

            }
            else if (filenameStart > 0)
            {
                //filename = line.Substring(filenameStart, line.Length - filenameStart - 1);
                filename = line.Substring(filenameStart, filenameend - filenameStart);
            }
            else // filename does not have quote
            {
                filenameStart = line.IndexOf('=') + 1;
                filename = line.Substring(filenameStart, line.Length - filenameStart);
            }

            AdvanceToEmptyLine(reader);
            if (!(string.IsNullOrEmpty(filename)))
            {

                if (!(filename.EndsWith(".13F"))) // ignore if the file of type 13F
                {
                    imageCount = imageCount + 1;
                }
            }
            //imageCount = imageCount + 1;
            if (imageCount < 2)
            {
                imageName = filename;
            }
            else
            {
                imageName = imageName + "#" + filename;
            }
            return filename;
        }