Question téléchargement Pièce jointe

Plus d'informations
il y a 10 ans 9 mois #20200 par chevalier
Bonjour,

je souhaite récupérer la pièce jointe d'un e-mail.
Cela fonctionne, bcp de personne explique comment faire mais j'ai tout de même un soucis, en effet quand la personne qui envoi le mail possède un signature avec image, le script récupéré les image de la signature...


Est il possible de distinguer cela?


$email = \"******\"
$username = \"*****\"
$password = \"*****\"
$domain = \"*******\"
$smtpServer = \"****8\"
$enc = New-Object System.Text.utf8encoding

#
connection a la BAL
[Reflection.Assembly]::LoadFile(\"C:\Interfaces\scripts\Robot\Microsoft.Exchange.WebServices.dll\")
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain)
$s.AutodiscoverUrl($email)

$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)

#create a property set (to let us access the body & other details not available from the FindItems call)
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(9999)
$searchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
$items = $inbox.FindItems($searchFilter, $view)


foreach ($item in $items.Items)
{

$item.load($psPropertySet)
$pj= $item.attachments

#echo $pj

#if ($pj.ContentId -eq $null #
# {
#echo \"ta mere\"
# }

$downloadDirectory = \"c:\sofinord\"
$item.Load()

foreach($attach in $item.Attachments){
$attach.Load()
if ($pj.ContentId -ne $null)
{
$fiFile = new-object System.IO.FileStream(($downloadDirectory + “\” + (Get-Date -Format \"ddMMyyyy\") + \"_\" + $attach.Name.ToString()), [System.IO.FileMode]::Create)
$fiFile.Write($attach.Content, 0, $attach.Content.Length)
$fiFile.Close()
echo $pj.ContentId
#write-host \"Downloaded Attachment : \" + (($downloadDirectory + “\” + (Get-Date -Format \"ddMMyyyy\") + \"_\" + $attach.Name.ToString()))
}
}
}



Une idée?

Merci et bonne journée

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 9 mois #20210 par Laurent Dardenne
Salut,
déterminer si le fichier est une image ?:
[code:1]
Function IsIconImage{
#valide si un fichier est du type attendu, ici un fichier Icon ( .ico )
param($Filename)
try
{
$Img = [System.Drawing.Image]::FromFile($Filename)
return $img.RawFormat.Equals([System.Drawing.Imaging.ImageFormat]::Icon)
}
catch [System.IO.FileNotFoundException], [System.OutOfMemoryException]
{
return $false;
}
finally {
if ($Img -ne $Null)
{$Img.Dispose()}
}
}#isIconImage

[/code:1]
Les formats reconnus :
[code:1][System.Drawing.Imaging.ImageFormat].GetMembers()|% {$_.name}[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 9 mois #20217 par Richard Lazaro
@Laurent:

Petit soucis, c'est que tu peux avoir desi mages en pièce jointe :p

En idée j'aurais :
Analyse du corps du mail (car surement en HTML) et essayer de détecter une signatures avec des images.
Si oui, retirer les images de la listes des pièces jointes qui sont récupérées.

Compliqué quand même ...

Think-MS : (Get-Life).Days | %{ Learn-More }

\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 9 mois #20219 par chevalier
Réponse de chevalier sur le sujet Re:téléchargement Pièce jointe
Laurent Dardenne écrit:

Salut,
déterminer si le fichier est une image ?:
[code:1]
Function IsIconImage{
#valide si un fichier est du type attendu, ici un fichier Icon ( .ico )
param($Filename)
try
{
$Img = [System.Drawing.Image]::FromFile($Filename)
return $img.RawFormat.Equals([System.Drawing.Imaging.ImageFormat]::Icon)
}
catch [System.IO.FileNotFoundException], [System.OutOfMemoryException]
{
return $false;
}
finally {
if ($Img -ne $Null)
{$Img.Dispose()}
}
}#isIconImage

[/code:1]
Les formats reconnus :
[code:1][System.Drawing.Imaging.ImageFormat].GetMembers()|% {$_.name}[/code:1]



oui image dans la signature :(

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 9 mois #20220 par chevalier
Réponse de chevalier sur le sujet Re:téléchargement Pièce jointe
Richard Lazaro écrit:

@Laurent:

Petit soucis, c'est que tu peux avoir desi mages en pièce jointe :p

En idée j'aurais :
Analyse du corps du mail (car surement en HTML) et essayer de détecter une signatures avec des images.
Si oui, retirer les images de la listes des pièces jointes qui sont récupérées.

Compliqué quand même ...


en effet compliqué :(

impossible de lire en mail en text brut et non html?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 9 mois #20221 par Richard Lazaro
Le problème des images de signature en pièce jointe provient le plus souvent de la transformation HTML => texte brut (si je ne m'abuse pas)

Think-MS : (Get-Life).Days | %{ Learn-More }

\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.090 secondes
Propulsé par Kunena