【问题标题】:Apostrophes contractions and escape char issues with Outlook DASL QueriesOutlook DASL 查询的撇号收缩和转义字符问题
【发布时间】:2018-11-18 18:05:12
【问题描述】:

我有一个用 C# 编写的 Outlook 插件,它可以扫描电子邮件,并将它们随机排列到不同的文件夹中。因为我们搜索的术语变化频繁,以至于将它们作为变量添加到程序中是完全不可接受的;最重要的是,列表很长! 我这样做是为了让代码从 CSV 中提取行并在 DASL 查询中使用该术语。

我的问题是,当我们需要搜索诸如“don't”、“haven't”、“shan't”、“Dave's”之类的词时,其他收缩或所有格名词会导致问题。我已经尝试了我能想到的一切来改善这个问题,不幸的是我不知所措。除非引入收缩,否则该程序可以完美运行。请帮忙:)

最相关的代码块是这样的:

         using (StreamReader r = new StreamReader(fileLoc))
        {
            //while != null to kill the loop
            string line;
            string prefix = @"@SQL=urn:schemas:httpmail:textdescription like '"; 
            string postfix = @"'";
            while ((line = r.ReadLine()) != null)
            {
                //slurp the csv line out, and spit it into DASL query.
                line = prefix + line + postfix;
                lines.Add(line);

            }
        } //closes out the streamreader object?
        string[] outputArray = lines.ToArray();
        return outputArray;

我的 CSV 文件如下所示:

%i do not%
%i flipped it%
%no thanks%

当我尝试添加 %don't do that% 或 %won't% 之类的内容时,我会遇到问题。

遗憾的是,我尝试过 %don't%、%"don't"%、%don/'t%、%dochr(39)t% 之类的方法,但均未成功。

如何使 DASL 查询使用撇号?而且,当它存在于 CSV 文件的记录中时,如何让它接受该撇号?

谢谢:)

编辑 这是我用来搜索带有 DASL 查询的电子邮件的模块,如果它可以帮助某人确定问题。

  public void SearchEmailBodyWithArray(string[] filter)
        {
            //this is the workhorse of this program
            MessageBox.Show("Pick Source Folder");
            Outlook.MAPIFolder olFolder = Application.Session.PickFolder();
            MessageBox.Show("Pick Destination Folder");
            Outlook.MAPIFolder destFolder = Application.Session.PickFolder();
            Outlook.Items items = olFolder.Items;
            Outlook.MailItem mailItem = null;

            object folderItem;
            string subjectName = string.Empty;

            int f = 0;
            while ( f < filter.Length)
            {
                folderItem = items.Find(filter[f]);
                while (folderItem != null)
                {
                    mailItem = folderItem as Outlook.MailItem;
                    if (mailItem != null)
                    {
                        subjectName += "\n" + mailItem.Subject;
                        mailItem.Move(destFolder);


                    }
                    folderItem = items.FindNext();
                }
                f++;
            }
            subjectName = " The following e-mail messages were found: " +
                subjectName;
            MessageBox.Show(subjectName);

        }

【问题讨论】:

    标签: c# visual-studio outlook-addin apostrophe


    【解决方案1】:

    我有一些处理撇号的 DASL 架构。 我的代码是 VBA,但查询可能是相同的,因为我们使用 Property-Acessor 对象使用的相同命名空间属性模式名称 - 根据 Sue Mosher @ MS Outlook 2007 Programming: JumpStart for Admin and PwrUsers, pg 503.

    Set myRestrictItems = myFolderContatos.Items.Restrict( _
                               "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/udfToAdd" & Chr(34) & " = 1 AND " _
                            & Chr(34) & "urn:schemas:contacts:bday" & Chr(34) & " = '" & "06 de abril de 1930" & "' AND " _
                            & Chr(34) & "urn:schemas:contacts:cn" & Chr(34) & " = " & ParseSpecialCharsAndDataTypeForSQL("Sérgio D'Or", False, False))
    

    当我执行 Debug.print ParseSpecialCharsAndDataTypeForSQL 时:

    ?ParseSpecialCharsAndDataTypeForSQL("Sérgio D'Or",False,False)
    'Sérgio D''Or'
    

    它找到了联系人:

    ?myRestrictItems.Count
    1
    

    继续,Jet Access 逃避撇号的老把戏是要走的路。

    希望对您有所帮助。

    附:我知道距您提出问题已有好几个月了,但仍然可以帮助某人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多