예제 #1
0
        BodyPartSplit(string response)
        {
            ImapMessageBodyPartList Parts = new ImapMessageBodyPartList();
            int i     = 0;
            int index = 1;
            int count = 0;

            do
            {
                int next = index;
                do
                {
                    if (response[next] == '(')
                    {
                        i++;
                    }
                    else if (response[next] == ')')
                    {
                        i--;
                    }
                    next++;
                } while (i > 0 || response[next - 1] != ')');
                if (i >= 0 && response[index] == '(')
                {
                    count++;
                    // Parse nested body parts
                    if (response.Substring(index, next - index).StartsWith("(("))
                    {
                        ImapMessageBodyPartList temp = BodyPartSplit(response.Substring(index, next));
                        for (int j = 0; j < temp.Count; j++)
                        {
                            temp[j].BodyPart = count.ToString() + "." + temp[j].BodyPart;
                            Parts.Add(temp[j]);
                        }
                    }
                    else
                    {
                        ImapMessageBodyPart Part = new ImapMessageBodyPart(response.Substring(index, next - index));
                        Part.BodyPart = count.ToString();
                        Parts.Add(Part);
                    }
                }
                else if (Parts.Count == 0)
                {
                    ImapMessageBodyPart Part = new ImapMessageBodyPart(response);
                    Part.BodyPart = "1";
                    Parts.Add(Part);
                }
                index = next;
            } while (i >= 0);
            return(Parts);
        }
예제 #2
0
 private ImapMessageBodyPartList BodyPartSplit(string response)
 {
     ImapMessageBodyPartList Parts = new ImapMessageBodyPartList();
     int i = 0;
     int index = 1;
     int count = 0;
     do
     {
         int next = index;
         do
         {
             if (response[next] == '(')
                 i++;
             else if (response[next] == ')')
                 i--;
             next++;
         } while (i > 0 || response[next - 1] != ')');
         if (i >= 0 && response[index] == '(')
         {
             count++;
             // Parse nested body parts
             if (response.Substring(index, next - index).StartsWith("(("))
             {
                 ImapMessageBodyPartList temp = BodyPartSplit(response.Substring(index, next));
                 for (int j = 0; j < temp.Count; j++)
                 {
                     temp[j].BodyPart = count.ToString() + "." + temp[j].BodyPart;
                     Parts.Add(temp[j]);
                 }
             }
             else
             {
                 ImapMessageBodyPart Part = new ImapMessageBodyPart(response.Substring(index, next - index));
                 Part.BodyPart = count.ToString();
                 Parts.Add(Part);
             }
         }
         else if(Parts.Count == 0)
         {
             ImapMessageBodyPart Part = new ImapMessageBodyPart(response);
             Part.BodyPart = "1";
             Parts.Add(Part);
         }
         index = next;
     } while (i >= 0);
     return Parts;
 }