2011-08-12 56 views
2

嗨我想寫一個需要閱讀電子郵件附件(普通文本)的Chrome擴展。我覺得這應該是可能的,因爲Gmail給你一個下載鏈接,但它不是一個直接的鏈接,這是否使它不可能?從Chrome擴展程序訪問Gmail附件?

我有下面的代碼讀取其中的作品只是不適合Gmail的遠程文件:

<script> 
var txtFile = new XMLHttpRequest(); 
txtFile.open("GET", "http://remote.com/remote_file", true); 
txtFile.onreadystatechange = function() { 
    if (txtFile.readyState === 4) { // Makes sure the document is ready to parse. 
    if (txtFile.status === 200) { // Makes sure it's found the file. 

     allText = txtFile.responseText; 
     lines = txtFile.responseText.split("\n"); // Will separate each line into an array 
     alert(allText) 
    } 
} 
} 
txtFile.send(null); 
</script> 

有誰知道我可以讀取Gmail附件這樣嗎? 謝謝

+0

來自控制檯的錯誤消息? – Skomski

+0

不幸的是沒有,但是如果我註釋掉if語句,警報只是返回一個空白警報。 –

+0

@RichardMosse你找到了這個解決方案?這是我的擴展所必需的。 –

回答

3

Gmail有一個鏈接到原始電子郵件源(「菜單顯示」)。不知道是否有可能以編程方式讀取它,但如果是這樣,我會嘗試解析原始消息源,並從那裏獲取附件(它們是base64編碼,我相信)。

+0

這很巧妙!謝謝 –

+1

@RichardMosse您是否找到了一種通過編程方式獲取電子郵件源的方法? – Peeja