0

Exchange Web サービスを使用して、Exchange メールサーバーから添付ファイルを抽出します。モノを使用してLinuxでコードを呼び出すと、特定のテキスト添付ファイルにいくつかの混合文字列が含まれています。

そのようです

"sam winglin vz" は "sainglin vz" になります。つまり、"m w" がありません。これは 150kb のファイルで約 3 回見られます。Linux の出力と Windows の出力では 3 バイトが欠落しています。

ビジュアルスタジオから抽出すると、テキストの添付は完璧です。

この例のように 、exchange の受信トレイから添付ファイルを保存します

これを修正するためにどの方向に目を向けるべきか考えていますか?

コード:

#r "Microsoft.Exchange.WebServices.dll"

open Microsoft
open Microsoft.Exchange.WebServices.Data
open System
open System.Net

type PgzExchangeService(url,user,password) =
    let service = new ExchangeService(ExchangeVersion.Exchange2007_SP1,
                                      TimeZoneInfo.CreateCustomTimeZone("Central Standard Time",new TimeSpan(-6, 0, 0),"(GMT-06:00) Central Time (US & Canada)","Central Standard Time"))


    do
       ServicePointManager.ServerCertificateValidationCallback <- ( fun _ _ _ _ -> true )
       service.Url <- new Uri(url)
       service.Credentials <- new WebCredentials(user, password, "domain")

    member this.Service with get() = service
    member this.InboxItems = this.Service.FindItems(WellKnownFolderName.Inbox, new ItemView(10))
    member this.GetFileAttachments ( item : Item ) =        
           let emailMessage = 
               EmailMessage.Bind( this.Service, 
                                  item.Id, 
                                  new PropertySet(BasePropertySet.IdOnly,    ItemSchema.Attachments))
           item, emailMessage.Attachments |> Seq.choose (fun attachment -> match box attachment with  
                                                                       | :? FileAttachment as x -> Some(x) | _ -> None)   

let mailAtdomain = new PgzExchangeService("https://xx.xx.XX.XX/EWS/Exchange.asmx", "user", "passw")

let printsave (item : Item ,att : seq<FileAttachment>) =
    if (Seq.length att) > 0 then
        printfn "%A - saving %i attachments" item.Subject (Seq.length att)        
        att |> Seq.iter ( fun attachment -> printfn "%A" attachment.Name 
                                            attachment.Load(@"/tmp/test/" + attachment.Name ) )   

// filter so we only have items with attachements and ...
let itemsWithAttachments = mailAtdomain.InboxItems                            
                           |> Seq.map mailAtdomain.GetFileAttachments 
                           |> Seq.iter printsave

TimeZoneInfo のバグにより、mono を使用する Windows ではコードが実行されません。


このサンプル コードは Linux で動作しますが、Windows では動作しません。TimeZoneInfo のバグのためです。しかし、これでLinux上で動作して添付ファイルを抽出するコード。csv 添付ファイルを試して、結果が同じかどうかを確認してください。私はデータを失います!数行ごとに約 3 バイト

問題を示すサンプルの csv 添付ファイルが必要な場合は、私にメールしてください

これは、テストに使用した ac# バージョンです。VS2010 から実行すると完璧に動作しますが、mono を使用する Linux では、添付ファイルのサイズが間違っています。一部のバイトが欠落しています?!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using System.Net;

namespace Exchange_SDP_Attachment_Extracter
{
    public class PgzExchangeService
    {
        public void Extract()
        {            
            ExchangeService service = new ExchangeService  (ExchangeVersion.Exchange2007_SP1,TimeZoneInfo.Local);
            service.Credentials = new NetworkCredential("user", "pass", "domain");
            service.Url = new Uri("https://xx.xx.xx.xx/EWS/Exchange.asmx");
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
            foreach (Item item in findResults.Items)
            {
                EmailMessage e = EmailMessage.Bind
                                 (service,
                                   item.Id,
                                   new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
                foreach ( Attachment att in e.Attachments )
                {

                    if (att is FileAttachment)
                    {
                        FileAttachment fileAttachment = (FileAttachment)att;
                        fileAttachment.Load(@"/tmp/testsdp/" + fileAttachment.Name);                        
                    }
                }

            }
        }
    }

    class Program
    {
         static void Main(string[] args)
         {
             PgzExchangeService pgz = new PgzExchangeService();
             pgz.Extract();
         }
      }
}
4

1 に答える 1

0

私の提案は、テキストの添付ファイルを 16 進エディタで調べてみることです。これらの 3 回の発生には何か異常があります。私たちがあなたに一連の行動を勧める前に、これらの 3 つの行の共通点を見つける必要があります。

于 2012-05-10T16:59:45.427 に答える